Lua 循环嵌套

更新时间: 2019-08-20 13:39

Lua 编程语言中允许循环中嵌入循环。以下实例演示了 Lua 循环嵌套的应用。

语法

Lua 编程语言中 for 循环嵌套语法格式:

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

Lua 编程语言中 while 循环嵌套语法格式:

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

Lua 编程语言中 repeat...until 循环嵌套语法格式:

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

除了以上同类型循环嵌套外,我们还可以使用不同的循环类型来嵌套,如 for 循环体中嵌套 while 循环。

实例

以下实例使用了for循环嵌套:

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("i 的值为:",i)
      end
   end
end

以上代码执行结果为:

i 的值为:    8
i 的值为:    9
i 的值为:    10

查看更多 Lua 循环

Using Google App Engine

Using Google App Engine

Charles Severance / O'Reilly Media / 2009-5-23 / USD 29.99

With this book, you can build exciting, scalable web applications quickly and confidently, using Google App Engine - even if you have little or no experience in programming or web development. App Eng......一起来看看 《Using Google App Engine》 这本书的介绍吧!

HTML 压缩/解压工具

HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JSON 在线解析

JSON 在线解析

在线 JSON 格式化工具

HEX CMYK 转换工具

HEX CMYK 转换工具

HEX CMYK 互转工具