4.10. Lua loop nesting

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

Lua loop is allowed to be embedded in a loop in a programming language. The following example demonstrates Lua application of loop nesting.

4.10.1. Grammar #

In the Lua programming language for loop nested syntax format:

for init,max/min value, increment
do
   for init,max/min value, increment
   do
      statements
   end
   statements
end

In the Lua programming language while loop nested syntax format:

while(condition)
do
   while(condition)
   do
      statements
   end
   statements
end

In the Lua programming language repeat...until loop nested syntax format:

repeat
   statements
   repeat
      statements
   until( condition )
until( condition )

In addition to the same type of loop nesting above, we can also use different loop types to nest, such as for nesting in the loop body while cycle.

4.10.2. Example #

The following example uses the for loop nesting:

Example #

j =2
for i=2,10 do
   for j=2,(i/j) , 2 do
      if(not(i%j))
      then
         break
      end
      if(j > (i/j))then
         print("The value of i is:",i)
      end
   end
end

The result of the above code execution is:

The value of i is: 8
The value of i is: 9
The value of i is: 10

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.