In The syntax format is as follows: The The following example is used in a judgment statement The output is as follows: As can be seen from the output, there is one more output The following example demonstrates the ability to set multiple statements in a The output is as follows: With The output is as follows:
Lua
language
goto
statement allows the control flow to be transferred unconditionally to the marked statement. 4.12.1. Grammar #
goto Label
Label
format is::: Label ::
goto
:Example 1 #
local a = 1
::label:: print("--- goto label ---")
a = a+1
if a < 3 then
goto label -- Jump to label when a is less than 3
end
--- goto label ---
--- goto label ---
---
goto
label
---
.
lable
:Example 2 #
i = 0
::s1:: do
print(i)
i = i+1
end
if i>3 then
os.exit() -- Exit when i is greater than 3
end
goto s1
0
1
2
3
goto
, we can implement the function of
continue
:Example 3 #
for i=1, 3 do
if i <= 2 then
print(i, "yes continue")
goto continue
end
print(i, " no continue")
::continue::
print([[i'm end]])
end
1 yes continue
i'm end
2 yes continue
i'm end
3 no continue
i'm end