Detailed explanation of the use of break statement in Lua

Time:2021-12-29

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.
grammar

The syntax of lua break statement is as follows:

 

Copy codeThe code is as follows:
break

 

example:

 

Copy codeThe code is as follows:
–[ local variable definition –]
a = 10–[ while loop execution –]
while( a < 20 )
do
   print(“value of a:”, a)
   a=a+1
   if( a > 15)
   then
      –[ terminate the loop using break statement –]
      break
   end
end

 

When you build and run the above code, it will produce the following results.

 

Copy codeThe code is as follows:
value of a: 10
value of a: 11
value of a: 12
value of a: 13
value of a: 14
value of a: 15

Recommended Today

JVM + GC parsing (premise knowledge concatenation)

Premise preparation JVM GC garbage collection JVM virtual machine monitoring, tuning and troubleshooting Tomcat and microservice optimization 1. Premise review 1.1. JVM memory structure 1.1.1、 JVM Architecture Overview The gray part in the figure isThread private, there is almost no garbage collectionOrange partThread sharing, the main place where garbage recycling occurs What is the class […]