tutorial on using Repeat...until loop statements in Lua

Source: Internet
Author: User
Tags lua

This article mainly introduces the Repeat...until Loop statement Usage Tutorial in Lua, is a basic tutorial in Lua's introductory learning, and needs friends to refer to the following

Unlike for and while loops, the loop condition is tested at the top of the loop, and the Repeat...until loop of the LUA programming language checks the state at the bottom of the loop.

The Repeat...until loop is similar to a while loop, which is different from do ... while loops are guaranteed to execute at least once.

Grammar

The syntax for the LUA programming language Repeat...until loops is:

The code is as follows:

Repeat

Statement (s)

Until (condition)

Note that the conditional expression appears at the end of the loop, so you test the condition before the Loop statement (S) executes once.

If the condition is false, the control process jump backup execution Loop statement (S) executes again. This process is repeated until the given condition becomes true.

Flow chart:

For example:

The code is as follows:

--[local variable definition--]

A = 10

--[repeat loop Execution--]

Repeat

Print ("Value of A:", a)

A = a + 1

Until (a > 15)

When the above procedure is established 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

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.