Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

IF - Arithmetic

Statement: Conditionally transfers control to one of three statements, based on the value of an arithmetic expression. The arithmetic IF statement is a deleted feature in the Fortran Standard. Intel® Fortran fully supports features deleted in the Fortran Standard.

IF (expr) label1,label2,label3

expr

Is a scalar numeric expression of type integer or real (enclosed in parentheses).

label1, label2, label3

Are the labels of valid branch target statements that are in the same scoping unit as the arithmetic IF statement.

Description

All three labels are required, but they do not need to refer to three different statements. The same label can appear more than once in the same arithmetic IF statement.

During execution, the expression is evaluated first. Depending on the value of the expression, control is then transferred as follows:

If the Value of expr is:

Control Transfers To:

Less than 0

Statement label1

Equal to 0

Statement label2

Greater than 0

Statement label3

Example

The following example transfers control to statement 50 if the real variable THETA is less than or equal to the real variable CHI. Control passes to statement 100 only if THETA is greater than CHI.

  IF (THETA-CHI) 50,50,100

The following example transfers control to statement 40 if the value of the integer variable NUMBERis even. It transfers control to statement 20 if the value is odd.

  IF (NUMBER / 2*2 - NUMBER) 20,40,20

The following statement transfers control to statement 10 for n < 10, to statement 20 for n = 10, and to statement 30 for n > 10:

  IF (n-10) 10, 20, 30

The following statement transfers control to statement 10 if n <= 10, and to statement 30 for n > 10:

  IF (n-10) 10, 10, 30