YouTip LogoYouTip

Lua Nested Loops

# Lua Nested Loops [![Image 3: Lua Loops](#) Lua Loops](#) The Lua programming language allows loops to be nested within loops. The following examples demonstrate the application of nested loops in Lua. ### Syntax The syntax for nested **for** loops in the Lua programming language: for init,max/min value, increment do for init,max/min value, increment do statements end statements end The syntax for nested **while** loops in the Lua programming language: while(condition)do while(condition) do statements end statements end The syntax for nested **repeat...until** loops in the Lua programming language: repeat statements repeat statements until( condition )until( condition ) In addition to nesting loops of the same type, we can also nest different loop types, such as nesting a while loop inside a for loop body. ### Example The following example uses nested for loops: ## 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("i The value is:",i) end end end The result of executing the above code is: i The value is:8 i The value is:9 i The value is:10 [![Image 4: Lua Loops](#) Lua Loops](#)
← Postgresql And Or ClausesPostgresql Expressions β†’