A detailed explanation of how break statements are used in LUA

Source: Internet
Author: User
Tags lua

This article mainly introduces the use of break statements in Lua, which is the basic knowledge of LUA's introductory learning, and needs friends to refer to the following

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

If you are using a nested loop (that is, another loop inside a loop), the break statement stops the execution of the innermost loop and begins the following segment of the next line of code that executes.

Grammar

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)

Todo

Print ("Value of A:", a)

A=a+1

if (a > 15)

Then

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

Break

End

End

When the above code is built and run, it produces 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.