13.07.2015 Views

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

Fortran 90/95 Programming Manual

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>Fortran</strong> <strong>90</strong>/<strong>95</strong> <strong>Programming</strong> <strong>Manual</strong>as in the following example:program integer_sum! this program sums a series of numbers given by the user! example of the use of the endless do constructimplicit noneinteger :: number, sumsum = 0doprint * , “give a number (type –1 to exit): “read * , numberif (number == -1) thenexitend ifsum = sum + numberend doprint * , “The sum of the integers is “, sumend program integer_sumThe name of the do loop can be specified in the exit statement. This is useful if you wantto exit a loop in a nested do loop construct:iloop: do i = 1, 3print * , "i: ", ijloop: do j = 1, 3print * , "j: ", jkloop: do k = 1, 3print * , "k: ", kif (k==2) thenexit jloopend do kloopend do jloopend do iloopWhen the exit statement is executed, the program continues at the next executablestatement after end do jloop. Thus, the first time that exit is reached is when i=1, j=1,k=2, and the program continues with i=2, j=1, k=1.A statement related to exit is the cycle statement. If a cycle statement is executed, theprogram continues at the start of the next iteration (if there are still iterations left to bedone).20

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

Saved successfully!

Ooh no, something went wrong!