【Lua】lua实现C# continue效果

1. repeat...until和break

lua 复制代码
for i = 1, 5 do
	repeat
	if i == 3 then
		break
	end
	print(i)
	until true
end

--[[
	1
	2
	4
	5
]]

2. 使用goto

lua 复制代码
for i = 1, 5 do
    if i == 3 then
        goto continue
    end
    print(i, " no continue")
    ::continue::
end

--[[
	1	 no continue
	3	 no continue
	4	 no continue
	5	 no continue
]]

3. 使用if...else...

lua 复制代码
for i = 1, 5 do
	if i ~= 3 then
		print(i)
	end
end

--[[
	1
	2
	4
	5
]]
相关推荐
哥不想学算法6 小时前
【C++】字符串字面量拼接
开发语言·c++
gugucoding8 小时前
21. 【C语言】打包不同类型:结构体
c语言·开发语言
Brookty8 小时前
【JavaEE】线程安全(一).4:写块串行保安全、CAS
java·开发语言·java-ee·多线程·线程安全
F20226974869 小时前
西门子 PLC 与 C# 通信
开发语言·c#
gugucoding9 小时前
31. 【C语言】堆栈与队列的实现
c语言·开发语言·数据结构·链表
万联WANFLOW10 小时前
多分支企业组网,IP 网段到底该怎么规划
开发语言·php
阿里嘎多学长10 小时前
2026-07-07 GitHub 热点项目精选
开发语言·程序员·github·代码托管
cookies_s_s12 小时前
C++ 字符串动态创建对象 -- 工厂模式、自动注册、模板递归动态调用
服务器·开发语言·c++
盐焗鹌鹑蛋13 小时前
【C++】继承
开发语言·c++