FORTRAN Reference Manual

Compiler Directives
FORTRAN Reference Manual528615-001
10-36
IF Compiler Directive
IF Compiler Directive
The IF directive identifies the beginning of a sequence of source records that
FORTRAN compiles only if a specified toggle is set. The compiler continues compiling
source records until it encounters either an ENDIF directive that specifies the same
toggle number as is specified in the IF directive or until it encounters the end of the
source file.
If the toggle specified on the IF directive is reset, FORTRAN skips all subsequent input
records until it encounters an ENDIF directive with the same toggle number as is
specified in the IF directive.
toggle
is a number in the range 1 through 15.
Considerations
Write the IF directive as the last item on a directive line.
If you have not set toggle with a SETTOG directive, the compiler skips the
source lines following the IF directive.
You cannot nest IF directives.
Once you have initiated skipping of source text using an IF directive, the compiler
skips source lines until the next matching ENDIF. Thus, the way to write an if-then-
else decision structure is:
?IF n
(statements to be compiled if toggle n is set)
?ENDIF n
?IFNOT n
(statements to be compiled if toggle n is reset)
?ENDIF n
The compiler prints a “#” character in the listing file to the left of each source line
that it skips as a result of an IF directive.
IF toggle