IF-ELSE Statement |
The IF-ELSE statement is a versatile way of creating execution branches within a function. It works in a similar way to the ternary operator, but can accept more complex input expressions.
IF condition_A do_A; [ELSE IF condition_B do_B;] [...] [ELSE]
condition_X | Some logic expression that can be evaluated to give a boolean result |
do_X | The code to execute if condition_X is true. If condition_X is true, do_X is executed and program flow jumps straight to the end of the IF block and any conditions after condition_X are not tested |
The following example sets the $myRegion variable to the suburb, if the suburb exists. If the suburb does not exist then $myRegion is set to the city. If both the city and suburb can not be found, then $myRegion will be set to "Unknown".
IF lookup(my_suburbs, %id) != NULL $my_region = lookup(my_suburbs, %id); ELSE IF lookup(my_cities, %id) != NULL $my_region = lookup(my_cities, %id); ELSE $my_region = "Unknown";