Lua if nested statements
if ... else statement
Lua if statement allows nesting, which means you can insert another if or else if statement if or else if a statement.
Lua if embedded statement syntax is as follows:
if( 布尔表达式 1)
then
--[ 布尔表达式 1 为 true 时执行该语句块 --]
if(布尔表达式 2)
then
--[ 布尔表达式 2 为 true 时执行该语句块 --]
end
end
You can use the same way nested else if ... else statement.
Examples
The following examples are used to determine the values of variables a and b:
--[ 定义变量 --] a = 100; b = 200; --[ 检查条件 --] if( a == 100 ) then --[ if 条件为 true 时执行以下 if 条件判断 --] if( b == 200 ) then --[ if 条件为 true 时执行该语句块 --] print("a 的值为 100 b 的值为 200" ); end end print("a 的值为 :", a ); print("b 的值为 :", b );
The above code is executed as follows:
a 的值为 100 b 的值为 200 a 的值为 : 100 b 的值为 : 200