contents.gifindex.gif

If-Then-Else Keyword

Syntax

IF expression THEN state_exp
[ ELSE state_exp ] ;

Chained IF-THEN-ELSE

IF expression THEN state_expression
ELSE IF expression THEN state_expression
ELSE IF expression THEN state_expression
ELSE state_expression ;

expression - Any valid expression.

state_exp - An expression identifying the next state, optionally followed by WITH transition equations.

Use

The IF-THEN-ELSE statement is an easy way to describe the progression from one state to another in a state machine. The expression following the IF keyword is evaluated, and if the result is true, the machine goes to the state indicated by the state_exp following the THEN keyword. If the result of the expression is false, the machine advances to the state indicated by the ELSE keyword.

Additional IF-THEN-ELSE statements can be chained to the ELSE clause of an IF-THEN-ELSE statement. Any number of IF-THEN-ELSE statements can be chained, but the final statement must end with a semicolon.


Note: Equation blocks used within a conditional expression, such as If-Then-Else, result in logic functions that are logically ANDed with the conditional expression that is in effect.


CAUTION: If-Then-Else is only supported within a state_diagram description. Use When-Then-Else for equations.

Example

If A==B then 2 ; "if A equals B goto state 2
if x-y then j else k; "if x-y is not 0 goto j, else goto k
if A then b*c; "if A is true (non-zero) goto state b*c

Chained If-Then-Else

if a then 1
else
if b then 2
else
if c then 3
else 0 ;


See Also

State_Diagram

Case

Goto

With