【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
]]
相关推荐
apcipot_rain2 小时前
C++转Java日记(06)
java·开发语言
SomeOtherTime9 小时前
Rust所有权(AI回答)
开发语言·后端·rust
Easyhood9 小时前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
白杨尚青10 小时前
C++进阶篇(六):map 和 set 的模拟实现——用红黑树封装 mymap/myset(迭代器 + operator[])
开发语言·c++·迭代器·stl·set·map·红黑树
饮水桶_T13 小时前
JAVA IO流笔记
开发语言·数据结构·算法
Felven16 小时前
C. Brr Brrr Patapim
c语言·开发语言
路溪非溪17 小时前
python标准库使用总结
开发语言·python
SomeOtherTime19 小时前
Rust 面向对象介绍(AI回答)
开发语言·python·rust
zh_xuan19 小时前
kotlin常见面试题
开发语言·kotlin·面试题
草莓熊Lotso20 小时前
【C++ 基于微服务的即时通讯系统】文件存储子服务实战:UUID生成、文件IO封装与全接口单元测试
开发语言·网络·数据库·c++·微服务·架构·单元测试