The IF statement allows decision logic to exist in a script. The code contained in an IF block is executed if the expression to be evaluated results in a TRUE condition. The following example illustrates code that is only executed if the IF expression evaluates to TRUE:
IF ($script.a == $script.b)
@script::log("they are the same")
ENDIF
An IF statement can have an ELSE clause that allows a block of code to be executed if the original expression evaluates to FALSE:
IF ($script.a == $script.b)
@script::log("they are the same")
ELSE
@script::log("they are not the same")
ENDIF
An IF statement can have an ELSE-IF clause that allows a block of code to be executed if the original expression evaluates to false:
IF ($script.a == $script.b)
@script::log("a and b are the same")
ELSE-IF($script.a == $script.c)
@script::log("a and c are the same")
ELSE
@script::log("a is not equal to b or c")
ENDIF
The expressions used to evaluate an IF or ELSE-IF supports multiple values. The following is an example of a multiple-value ELSE-IF statement; if both expressions evaluate to TRUE then the log statement is executed.
IF (($script.a == $script.b) && ($script.a == $script.c))
@script::log("a, b and c are all the same")
ENDIF
The following is an example of a multiple-value ELSE-IF statement; if either expression evaluates to TRUE then the log statement is executed:
IF (($script.a == $script.b) || ($script.a == $script.c))
@script::log("a and b OR a and c are the same")
ENDIF