if()

Evaluates a condition and executes a function based on the result.

Hint: Use exec function to execute block.

Syntax

if(condition, iftrue)
if(condition, iftrue, iffalse)

Parameters

Parameter Type Description
condition Any The condition to evaluate.
iftrue Any The function to execute if the condition is true.
iffalse Any (Optional) The function to execute if false. optional

Return Value

Examples

Execute a function if the condition is true

if(1==1, print("Hey, this is true!"));

Output:
Hey, this is true!

Execute one of two functions based on the condition

if(1==2, print("Hey, this is true!"), print("Liar, this is false!"));

Output:
Liar, this is false!

See also

exec