If
If
If[cond] ... Else ... End checks the condition and executes a script block based on the result.
Note
If an expression in an if statement is indeterminate, it is treated as if it were True.
Usages
If[cond] ... End
If[cond] ... End executes the script at ... unless cond evaluates to False.
| Example | in |
|---|---|
The script at ... is not executed, given x==4 is False. |
x:=3 |
The script at ... is executed, given x==4 is indeterminate. |
If[x==4] |
If[cond] ... Else ... End
If[cond] ... Else ... End executes the script after If, if cond evaluates to True. If cond evaluates to False, it executes the script after Else instead.
| Example | in |
|---|---|
The Else block is executed, given x==4 is False. |
x:=3 |
The If block is executed, given x==4 is indeterminate. |
If[x==4] |
If[cond1] ... ElseIf[cond1] ... Else ... End
If[cond1] ... ElseIf[cond1] ... Else ... End executes the script after If, if cond1 evaluates to True. If cond1 evaluates to False, but cond2 evaluates to True, it executes the script after ElseIf instead. If both cond1 and cond2~ evaluate to False, it executes the script after Else.
| Example | in |
|---|---|
The ElseIf block is executed, given x==4 is False. Next, it will choose to go either for the If or the Else statement of the inner block. |
x:=3 |