Lua When the Boolean expression is The The following example is used to determine a variable The execution result of the above code is as follows: if statement consists of a Boolean expression as a conditional judgment, followed by other statements. 4.14.1. The syntax format of the Lua if statement is as follows: #
if(Booleans) then --[Statement executed when Boolean expression is true --] end
true at that time if block of code in is executed, when the Boolean expression is false , follow closelyat the if statement end , the subsequent code will be executed. Lua believes that false and nil are false, while true and non nil are true. It should be noted that 0 in Lua is true . if statement flow chart is as follows:
Example #
a is the value less than 20: 4.14.2. Example #
--[Define variables --] a = 10; --[ Using the if statement --] if( a < 20 ) then --[ Print the following information when the if condition is true --] print("A less than 20" ); end print("The value of a is:", a);
A less than 20 The value of a is: 10