Next: Attributes for DO statements
Up: Various attributes and functions
Previous: Attributes for labels
Attributes for conditional statements
Conditionnal statements are coded by several variants:
- The variant "struct_if" refers to a IF-THEN-ELSE
statement.
IF (X.EQ.Y) THEN
PRINT *,X
ENDIF
- The variant "struct_elseif" refers to a ELSEIF statement in a
IF-THEN-ELSE statement.
IF (X.EQ.Y) THEN
PRINT *,X
ELSEIF (X.EQ.Z) THEN
PRINT *,Z
ENDIF
- The variant "log_if" refers to a IF statement applied to only one simple
statement.
IF (X.EQ.Y) PRINT *,X
- The variant "arith_if" refers to an labeled IF
statement.
IF (X.EQ.Y) 10,20,30
- The variant "do" refers to an iterative statement. It can be considered
as a conditionnal statement when the variant of its bounds part is "while"
(see BOUND).
DO WHILE (X.EQ.Y)
PRINT *,X
ENDDO
The following attributes gives a quick access to the most useful parts of
conditionnal statements.
-
stat.CONDITION
-
The expression returns the condition
associated to a conditionnal statement.
-
stat.THENCLAUSE
-
The expression returns the THEN branch
of the statement stat of variant "struct_if" or "struct_elseif".
-
stat.ELSECLAUSE
-
The expression returns the ELSE branch
of the statement stat of variant "struct_if" or "struct_elseif".
-
stat.STATEMENT
-
The expression returns the statement
associated to the statement stat of variant "log_if". (see section
8.1 for more informations).
Example 43:The following script inverts the condition and exchanges the branches of an IF-THEN-ELSE
statement
SCRIPT InvertIf()
stat := $cstat
IF (stat.VARIANT=="struct_if") THEN
stat.CONDITION <- PARSEEXPR(".NOT.(%e)",stat.CONDITION)
thenpart := stat.THENCLAUSE
stat.THENCLAUSE <- stat.ELSECLAUSE
stat.ELSECLAUSE <- thenpart
ENDIF
ENDSCRIPT
Next: Attributes for DO statements
Up: Various attributes and functions
Previous: Attributes for labels
Yann Mevel
1999-04-30