4.6. Lua cycle

发布时间 : 2025-10-25 13:34:07 UTC      

Page Views: 10 views

In many cases, we need to do some regular repetitive operations, so we need to repeat some statements in the program.

A group of statements that are repeatedly executed are called loop bodies, and whether they can be repeated or not determines the termination conditions of the loop.

The loop structure is the process structure that repeatedly executes a certain program under certain conditions, and the program that is executed repeatedly is called the loop body.

The loop statement consists of two parts: the body of the loop and the termination condition of the loop.

Image0

Lua language provides the following loop processing methods:

Cycle type

Description

While cycle

Have the program execute certain statements repeatedly when the condition istrue. Check whether the condition is true before executing the statement.

For cycle

The specified statement is executed repeatedly, and the number of repetitions can be controlled in the for statement.

repeat…until

Repeat the loop until the specified condition is true

Loop nesting

You can nest one or more loop statements within a loop (while do… End;for… Do… End;repeat… Until;)

4.6.1. Loop control statement #

The loop control statement is used to control the flow of the program in order to realize the various structures of the program.

Lua supports the following loop control statements:

Control statement

Description

Break statement

Exits the current loop or statement and starts the script to execute the following statement.

Goto statement

Transfer the control point of the program to a label.

4.6.2. Infinite cycle #

In the body of a loop, if the condition is always true , the loop statement will be executed forever, as follows while loops as an example:

Example #

while( true ) do print("The loop will always execute") end 
《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。