LF Fortran 95

Arithmetic IF Statement (obsolescent)


Execution of an arithmetic IF statement causes evaluation of an expression followed by a transfer of control. The branch target statement identified by the first, second, or third label is executed if the value of the expression is less than zero, equal to zero, or greater than zero, respectively.


IF (expr) label, label, label


expr is a scalar numeric expression.
label is a statement label.


Each label must be the label of a branch target statement that appears in the same scoping unit as the arithmetic IF statement.

expr must not be of type COMPLEX.

The same label can appear more than once in one arithmetic IF statement.

The arithmetic IF statement is an ancient construct created in the early days of Fortran, and was suitable for the tiny programs which the machines of that era were able to execute. As hardware got better and programs grew larger, the arithmetic IF statement was identified as one of the main contributors to a logic snarled condition known as "spaghetti code", which made a program difficult to read and debug. The arithmetic IF statement was replaced by the IF Construct. While the arithmetic IF statement is obsolescent and should never be used when writing new code, it is fully supported.


real :: b=1.d0 10 write(*,*) " arithmetic if construct" if (b) 20,10,30 20 write(*,*) " if b < 0, control is transferred here" 30 write(*,*) " if b > 0, control is transferred here" write(*,*) " equivalent if construct" if( b < 0. ) then write(*,*) "if b < 0, control is transferred here" else if ( b > 0. ) then write(*,*) " if b > 0, control is transferred here" else write(*,*) " if b=0, control is transferred here" end if

See Also

IF Construct