If

From LuaSTG Wiki
Jump to navigation Jump to search
If, then and else Icon
If.pngThen.pngElse.png
If Icon
Location General Tab

If is a kind of control statement. It can be used to control a process that only happens under certain conditions.

It requests a boolean argument, if this argument returns a true result, it will execute the sub-statements of then statement, if this argument returns a false result, 'twill execute the sub-statements of else statement.

An if statement will be translated to a Lua if statement when the script is run, which is something like "if condition then doStuff end", where the condition is the condition entered in the if node, and doStuff are the code inside the if node body.


Example[edit | edit source]

SampleIf.png


Version Differences[edit | edit source]

  • Since version ex+, else statement can get a boolean argument, it means that this else statement will be used as an else if statement, if neither the condition in this statement is not satisfied, it won't be executed.
  • Since version ex+, else statement can be copy and pasted as a sub-statement of If statement.