else
Allows you to use the IF, ELSE, ELSEIF, and END commands to execute a group of commands conditionally. The execution of commands bracketed by IF and END depends on the value of an expression.
You can use the IF command with or without the ELSE command.
Format:
else |
|---|
if condition = | (expression)...end |
if condition = | (expression)...else...end |
Example:
if condition=(DB_EXISTS ("MAR1"))
marker modify marker=mar1 location=2,0,0
else
marker create marker=mar1 location=2,0,0
end
In the above example, if the marker MAR1 exists, Adams View modifies its location. If the marker does not exist, Adams View creates it and sets its location.
Extended Definition:
1. The question-mark/colon (?:) operator, used in a conditional expression, replaces an IF/ELSE command that distinguishes one of two values. The expression consists of three parts: a condition whose truth determines which value is selected, and two expressions for the values.
condition expression ? expression a : expression b
When evaluated, the conditional operator takes on one of the two values. The expression that comes before the question-mark is interpreted as boolean-valued. If it is true (non-zero), then expression a is used as the value of the conditional operator, otherwise expression b is used as the value.
For example, consider the commands below:
if condition = (variable_a < variable_b)
variable set variable = variable_min real = (EVAL(variable_a))
else
variable set variable = variable_min real = (EVAL(variable_b))
end
This can be expressed more concisely by using a ?: conditional operator:
variable set variable = variable_min &
real = (EVAL((variable_a < variable_b)? variable_a : variable_b))