Lua 流程控制

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

Lua 编程语言流程控制语句通过程序设定一个或多个条件语句来设定。在条件为 true 时执行指定程序代码,在条件为 false 时执行其他指定代码。

以下是典型的流程控制流程图:

控制结构的条件表达式结果可以是任何值,Lua认为false和nil为假,true和非nil为真。

要注意的是Lua中 0 为 true:

--[ 0 为 true ]
if(0)
then
    print("0 为 true")
end

以上代码输出结果为:

0 为 true

Lua 提供了以下控制结构语句:

语句 描述
if 语句 if 语句 由一个布尔表达式作为条件判断,其后紧跟其他语句组成。
if...else 语句 if 语句 可以与 else 语句搭配使用, 在 if 条件表达式为 false 时执行 else 语句代码。
if 嵌套语句 你可以在ifelse if中使用一个或多个 ifelse if 语句 。
Data Structures and Algorithms in Java

Data Structures and Algorithms in Java

Michael T. Goodrich、Roberto Tamassia / Wiley / 2010-01-26 / USD 177.41

* This newest edition examines fundamental data structures by following a consistent object-oriented framework that builds intuition and analysis skills of data structures and algorithms * Presents ne......一起来看看 《Data Structures and Algorithms in Java》 这本书的介绍吧!

在线进制转换器

在线进制转换器

各进制数互转换器

Base64 编码/解码

Base64 编码/解码

Base64 编码/解码

HEX CMYK 转换工具

HEX CMYK 转换工具

HEX CMYK 互转工具