02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Execution control<br />

Control constructs and statement blocks<br />

6. The normal flow of execution resumes with the first executable statement following the<br />

END SELECT statement, unless a statement in statement-block transfers control.<br />

Example<br />

The following CASE construct prints an error message according to the value of ios_err:<br />

INTEGER :: ios_err<br />

...<br />

SELECT CASE (ios_err)<br />

CASE (:900)<br />

PRINT *, ”Unknown error”<br />

CASE (913)<br />

PRINT *, ”Out of free space”<br />

CASE (963:971)<br />

PRINT *, ”Format error”<br />

CASE (1100:)<br />

PRINT *, ”ISAM error”<br />

CASE DEFAULT<br />

PRINT *, ”Miscellaneous Error”<br />

END SELECT<br />

DO construct<br />

The DO construct repeatedly executes a statement block. The syntax of the DO statement<br />

provides two ways to specify the number of times the statement block executes:<br />

Byspecifyingaloopcount.<br />

By testing a logical expression as a condition for executing each iteration.<br />

You can also omit all control logic from the DO statement, in effect creating an infinite loop.<br />

The following sections describe the three variations of the DO construct.<br />

You can use the CYCLE and EXIT statements to alter the execution logic of the DO construct.<br />

For information about these statements, see “Flow control statements” on page 113.<br />

Counter-controlled DO loop<br />

A counter-controlled DO loop uses an index variable to determine the number of times the loop<br />

executes.<br />

Syntax<br />

[ construct-name : ] DO index = init, limit [ , step ]<br />

statement-block<br />

END DO [ construct-name ]<br />

<strong>HP</strong> <strong>Fortran</strong> also supports the older, FORTRAN 77-style syntax of the DO loop:<br />

Chapter 6 107

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

Saved successfully!

Ooh no, something went wrong!