4.12. Lua goto statement

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

Page Views: 10 views

In Lua language goto statement allows the control flow to be transferred unconditionally to the marked statement.

4.12.1. Grammar #

The syntax format is as follows:

goto Label 

The Label format is:

:: Label :: 

The following example is used in a judgment statement goto :

Example 1 #

local a = 1 ::label:: print("--- goto label ---") a = a+1 if a < 3 then goto label -- Jump to label when a is less than 3 end 

The output is as follows:

--- goto label --- --- goto label --- 

As can be seen from the output, there is one more output --- goto label --- .

The following example demonstrates the ability to set multiple statements in a lable :

Example 2 #

i = 0 ::s1:: do print(i) i = i+1 end if i>3 then os.exit() -- Exit when i is greater than 3 end goto s1 

The output is as follows:

0 1 2 3 

With goto , we can implement the function of continue :

Example 3 #

for i=1, 3 do if i <= 2 then print(i, "yes continue") goto continue end print(i, " no continue") ::continue:: print([[i'm end]]) end 

The output is as follows:

1 yes continue i'm end 2 yes continue i'm end 3 no continue i'm end 
《地理信息系统原理、技术与方法》  97

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