06.03.2014 Views

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

Intel Fortran Language Reference - NCI National Facility

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Execution Control 7<br />

Form<br />

Example<br />

block1a INAVG = INAVG + 1<br />

ELSE<br />

ELSE<br />

block1b OUTAVG = OUTAVG + 1<br />

END IF<br />

END IF<br />

ELSE<br />

ELSE<br />

block2 OUTRAN = OUTRAN + 1<br />

END IF<br />

END IF<br />

If A is less than 100, the code immediately following the IF is executed. This code contains a<br />

nested IF construct. If the absolute value of A minus AVG is less than or equal to 5, block1a is<br />

executed. If the absolute value of A minus AVG is greater than 5, block1b is executed.<br />

If A is greater than or equal to 100, block2 is executed, and the nested IF construct (in block1) is<br />

not executed.<br />

The following example shows a named IF construct:<br />

BLOCK_A: IF (D > 0.0) THEN ! Initial statement for named construct<br />

RADIANS = ACOS(D)<br />

! These two statements<br />

DEGREES = ACOSD(D) ! form a block<br />

END IF BLOCK_A<br />

! Terminal statement for named construct<br />

IF Statement<br />

The IF statement conditionally executes one statement based on the value of a logical expression.<br />

(This statement was called a logical IF statement in FORTRAN 77.)<br />

The IF statement takes the following form:<br />

IF (expr) stmt<br />

expr<br />

Is a scalar logical expression enclosed in parentheses.<br />

stmt<br />

Is any complete, unlabeled, executable <strong>Fortran</strong> statement, except for the following:<br />

• A CASE, DO, IF, FORALL, or WHERE construct<br />

• Another IF statement<br />

• The END statement for a program, function, or subroutine<br />

7-31

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!