This is the most basic form of conditional execution in that there is only an option to execute one statement or not -- the general IF construct allows a block of code to be executed. The basic form is,
IF(logical-expression
)
exec-stmt
![]()
If the boolean expression, logical-expression
, evaluates to
.TRUE.
then the
exec-stmt
is executed otherwise control of the program
passes to the next line. This type of IF statement still has its use
as it is a lot less verbose than a block-IF with a single executable
statement.
For example,
IF (bool_val) A = 3
A logical expression is often expressed as:
expression
![]()
relational-operator
![]()
expression
![]()
For example,
IF (bool_val) A = 3 IF (x .GT. y) GOTO 56 IF (i .NE. 0 .AND. j .EQ. 0) k = 1/(k*j) IF (i /= 0 .AND. j == 0) k = 1/(k*j) ! sameAs REAL numbers are represented approximately, it makes little sense to use the .EQ. and .NE. relational operators between real-valued expressions. For example there is no guarantee that 3.0 and 1.5 * 2.0 are equal. If two REAL numbers / expressions are to be tested for equality then one should look at the size of the difference between the numbers and see if this is less than some sort of tolerance.
IF (ABS(a-b) .LT. Tol) same = .TRUE.