Detailed description of the use of the break statement in Lua

Source: Internet
Author: User

Detailed description of the use of the break statement in Lua

This article describes how to use the break statement in Lua. It is the basic knowledge of Lua. For more information, see

When a break statement is encountered in a loop, the loop is terminated immediately, and the program control continues after the next loop statement.

If you are using a nested loop (that is, another loop in one loop), the break statement stops the execution of the innermost loop and starts the execution of the next code line.

Syntax

The Lua break statement syntax is as follows:

The Code is as follows:

Break

Example:

The Code is as follows:

-- [Local variable definition --]

A = 10 -- [while loop execution --]

While (a <20)

Do

Print ("value of a:",)

A = a + 1

If (a> 15)

Then

-- [Terminate the loop using break statement --]

Break

End

End

When the above Code is created and run, it will produce the following results.

The 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.