English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Chinese Reference Manual

Lua Loops

Lua programming language break statement

If you use nested loops, the break statement will stop the execution of the innermost loop and start executing the outer loop statement.

Syntax

In the Lua programming language break Syntax format:

break

Flowchart:

Online Example

The following example executes a while loop, where the variable a is less than 2Output the value of a when 0, and when a is greater than 15 Execution stops when the loop is terminated:

--[Define variable --]
a = 10
--[While loop --]
while(a < 20)
do
   print("The value of a is:", a)
   a=a+1
   if(a > 15)
   then
      --[Use the break statement to terminate the loop --]
      break
   end
end

The execution result of the above code is as follows:

The value of a is:    10
The value of a is:    11
The value of a is:    12
The value of a is:    13
The value of a is:    14
The value of a is:    15

Lua Loops