elseif
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 nest any combination of looping (FOR/END, WHILE/END) and conditional constructs (IF/ELSEIF/ELSE/END).
Note: | As with all Adams View commands, you can use the IF, ELSE, ELSEIF, and END commands on the command line, in macros, and in command files. |
Format:
elseif |
|---|
if condition = | (expression) |
elseif condition = | (expression) |
else | (optional) |
end | |
Example:
! Bodies
variable create variable=object_type string=(eval(DB_TYPE(.MDI.obj)))
if condition=(object_type == "marker")
interface command_builder command="marker modify marker" initial=(.MDI.obj)
elseif condition=(object_type == "point")
interface dialog display dialog=.gui.main_objecttable parameter="Points"
elseif condition=(object_type == "flexible_body")
interface dialog display dialog=.gui.flx_dia_panel parameter=(.MDI.obj)
! Constraints - complex joints
elseif condition=(object_type == "coupler" )
interface dialog display dialog=.gui.coupler_cremod parameter=(.MDI.obj)
elseif condition=(object_type == "gear" )
interface command_builder command="constraint modify complex_joint gear" initial=(.MDI.obj)
! Constraints - Higher Pair contact
elseif condition=(object_type == "curve_curve" )
interface command_builder command="constraint modify higher_pair_contact curve_curve" init=(.MDI.obj)
elseif condition=(object_type == "point_curve" )
interface command_builder command="constraint modify higher_pair_contact point_curve" init=(.MDI.obj)
end
The above example illustrates how to use ELSEIF to determine the type of object and then perform an operation on the object, based on the object's type. The example assumes that an Adams View variable named .mdi.org exists and its type is database object.
Description:
Parameter | Value Type | Description |
|---|
Condition | Expression | If the expression evaluates to a non-zero value, Adams View executes the commands following the IF or ELSEIF command up to the ELSE, when present, or the END, if you do not use the ELSE. If the expression evaluates to zero and you used ELSE, Adams View executes the commands between the ELSE and the END commands. |
Tips:
1. You can have any number of ELSEIF CONDITION commands.
2. 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))