When a break statement is encountered in the loop, the loop terminates immediately and program control continues after the next loop statement.
If you are using a nested loop (that is, another loop within one loop), the break statement will stop the execution of the innermost loop and start the program back section of the next line of code.
The syntax of lua break statement is as follows:
a = 10–[ while loop execution –]
while( a < 20 )
print(“value of a:”, a)
if( a > 15)
–[ terminate the loop using break statement –]
When you build and run the above code, it will produce the following results.
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15