The usage of the while LOOP statement in Lua

Source: Internet
Author: User

The usage of the while LOOP statement in Lua

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

The while LOOP statement in Lua programming language repeats the target statement if the given condition is true.

Syntax

The while LOOP syntax in Lua programming language is:

The Code is as follows:

While (condition)

Do

Statement (s)

End

Here, the declaration (S) can be a single statement or statement block. This condition can be any expression and is actually any non-zero value. Loop iteration when the condition is true.

If the condition is false, the program controls the line following the loop.

Flowchart:

Here, the key point in the while loop is that the loop may not run forever. When the condition test result is false, the loop body is skipped, and the first statement after the loop is executed.

For example:

The Code is as follows:

A = 10

While (a <20)

Do

Print ("value of a:",)

A = a + 1

End

When the above Code is compiled and executed, 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

Value of a: 16

Value of a: 17

Value of a: 18

Value of a: 19

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.