English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Lua if statements allow nesting, which means you can insert other if or else if statements within an if or else if statement.
The syntax format of Lua nested if statements is as follows:
if(Boolean expression 1) then --[ Boolean expression 1 Execute this statement block if --] if(Boolean expression 2) then --[ Boolean expression 2 Execute this statement block if --] end end
You can nest them in the same way else if...else Statement.
The following example is used to judge the values of variables a and b:
--[ Define variables --] a= 100; b= 200; --[ Check the condition --] if(a== 100) then --[ Execute the following if condition judgment if the condition is true --] if(b== 200) then --[ Execute this statement block if the condition is true --] print("The value of a is 100 The value of b is 200"); end end print("The value of a is:", a); print("The value of b is:", b);
The execution result of the above code is as follows:
The value of a is 100 The value of b is 200 The value of a is: 100 The value of b is: 200