02.07.2013 Views

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

HP Fortran Programmer's Reference

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.

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

DO<br />

DO i = 1, 10<br />

WRITE (*, *) i<br />

END DO<br />

The next example is a FORTRAN 77-style DO loop that does the same as the preceding<br />

example:<br />

DO 50 i = 1, 10<br />

WRITE (*, *) i<br />

50 CONTINUE<br />

The following DO construct iterates 5 times, decrementing the loop index from 10 to 2:<br />

DO i = 10, 1, -2<br />

END DO<br />

The following is an example of a DO WHILE loop:<br />

DO WHILE (sum < 100.0)<br />

sum = sum + get_num(unit)<br />

END DO<br />

The following example illustrates the use of the EXIT statement to exit from a nested DO loop.<br />

The loops are named to control which loop is exited. Note that loop-control is missing from<br />

both the inner and outer loops, which therefore can be exited only by means of one of the EXIT<br />

statements:<br />

outer:DO<br />

READ *, val<br />

new_val = 0<br />

inner:DO<br />

new_val = new_val + proc_val(val)<br />

IF (new_val >= max_val) EXIT inner<br />

IF (new_val == 0) EXIT outer<br />

END DO inner<br />

END DO outer<br />

The next DO construct never executes:<br />

DO i = 10, 1<br />

END DO<br />

Related statements<br />

CONTINUE, CYCLE, END (construct), and EXIT<br />

Related concepts<br />

For related information, see the following:<br />

294<br />

“DO construct” on page 107<br />

Chapter 10

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

Saved successfully!

Ooh no, something went wrong!