Lua while 循环

Lua 教程 · 2019-02-27 17:12:12

Lua 编程语言中 while 循环语句在判断条件为 true 时会重复执行循环体语句。

语法

Lua 编程语言中 while 循环语法:

while(condition)
do
   statements
end

statements(循环体语句) 可以是一条或多条语句,condition(条件) 可以是任意表达式,在 condition(条件) 为 true 时执行循环体语句。

流程图如下:

在以上流程图中我们可以看出在condition(条件)为 false 时会跳过当前循环并开始脚本执行紧接着的语句。

实例

以下实例循环输出 a 的值:

a=10
while( a < 20 )
do
   print("a 的值为:", a)
   a = a+1
end

执行以上代码,输出结果如下:

a 的值为:    10
a 的值为:    11
a 的值为:    12
a 的值为:    13
a 的值为:    14
a 的值为:    15
a 的值为:    16
a 的值为:    17
a 的值为:    18
a 的值为:    19

点击查看所有 Lua 教程 文章: https://www.codercto.com/courses/l/21.html

查看所有标签

The Definitive Guide to MongoDB

The Definitive Guide to MongoDB

Peter Membrey、Wouter Thielen / Apress / 2010-08-26 / USD 44.99

MongoDB, a cross-platform NoSQL database, is the fastest-growing new database in the world. MongoDB provides a rich document orientated structure with dynamic queries that you’ll recognize from RDMBS ......一起来看看 《The Definitive Guide to MongoDB》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

在线进制转换器
在线进制转换器

各进制数互转换器

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码