Skip to main content

6.7) Understanding Loops (cont'd)


A loop enables you to do this process (i.e. print, or any process you can code) over and over. The same bit of code using a loop would be:

       integer :: i
       do i=1,100
          print *, i
       enddo

Remember of indent line 3 so you can easily see that the loop starts on line 2 and ends on line 4.

Line 2 of the code defines the loop. It will loop around 100 times starting at 1. The loop starts with a do on line 2 and it loops back once it reaches the enddo on line 4.

This program is explained step by step on the next page.