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.

<strong>HP</strong> <strong>Fortran</strong> statements<br />

DO<br />

When label is present in the DO statement, it specifies the label of the terminating statement<br />

of the DO loop. The terminating statement cannot be any of the following statements:<br />

GO TO (unconditional)<br />

GO TO (assigned)<br />

IF (arithmetic)<br />

IF (block)<br />

ELSE or ELSE IF<br />

END, END IF, END SELECT, orEND WHERE<br />

RETURN<br />

STOP<br />

DO<br />

Any nonexecutable statement<br />

Note, however, that the terminating statement can be an IF (logical) or an END DO statement.<br />

To maintain compatibility with some older versions of <strong>Fortran</strong>, you can use the +onetrip<br />

compile-line option to ensure that every counter-controlled DO loop in the program executes at<br />

least once.<br />

Extended-range DO loops<br />

Extended-range DO loops—a compatibility extension—allow a program to transfer control<br />

outside the DO loop’s range and then back into the DO loop. Extended-range DO loops work as<br />

follows: if a control statement inside a DO loop transfers control to a statement outside the DO<br />

loop, then any subsequent statement can transfer control back into the body of the DO loop.<br />

For example, in the following code, the range of the DO loop is extended to include the<br />

statement GOTO 20, which transfers control back to the body of the DO loop:<br />

DO 50 i = 1, 10<br />

20 n = n + 1<br />

IF (n > 10) GOTO 60<br />

50 CONTINUE ! normally, the range ends here<br />

60 n = n + 100 ! this is the extended range,<br />

GOTO 20 ! which extends down to this line<br />

Examples<br />

The following DO construct displays the integers 1 through 10:<br />

Chapter 10 293

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

Saved successfully!

Ooh no, something went wrong!