The use of While loop statements in Lua

Source: Internet
Author: User
Tags lua

This article focuses on the use of while loop statements in Lua, the basics of Lua's introductory learning, and the need for friends to refer to

A while loop statement in the LUA programming language that repeats the target statement whenever a given condition is true.

Grammar

The syntax for a while loop in the LUA programming language is:

The code is as follows:

while (condition)

Todo

Statement (s)

End

Here, the declaration (S) can be a single statement or block of statements. The condition can be any expression, and it is really any value that is not 0. Loop iterations when the condition is true.

When the condition is false, the program control enters the row immediately after the loop.

Flow chart:

Here, the key point in the while loop is that the loop may not run forever. When the condition test results are 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)

Todo

Print ("Value of A:", a)

A = A+1

End

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

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.