In the Lua programming language In the Lua programming language In the Lua programming language In addition to the same type of loop nesting above, we can also use different loop types to nest, such as The following example uses the The result of the above code execution is: Lua loop is allowed to be embedded in a loop in a programming language. The following example demonstrates Lua application of loop nesting. 4.10.1. Grammar #
for loop nested syntax format:for init,max/min value, increment do for init,max/min value, increment do statements end statements end
while loop nested syntax format:while(condition) do while(condition) do statements end statements end
repeat...until loop nested syntax format:repeat statements repeat statements until( condition ) until( condition )
for nesting in the loop body while cycle. 4.10.2. Example #
for loop nesting:Example #
j =2 for i=2,10 do for j=2,(i/j) , 2 do if(not(i%j)) then break end if(j > (i/j))then print("The value of i is:",i) end end end
The value of i is: 8 The value of i is: 9 The value of i is: 10