4.12. Lua goto statement

发布时间 : 2023-10-12 23:00:02 UTC      

Page Views: 65 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
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.