166. Beware of a loop to huge(i), since huge(i)+1 is out of range.#

topic: Loops

Note

This tip is a draft1.

To loop from 1 to a large number, with the loop terminated by an EXIT, write

do i=1,huge(i)-1 ! code if (cond) exit end do

It is invalid for the upper bound to be huge(i), since i is set to huge(i)+1 upon exit, which is out of range.



1

From the perspective of FortranTip Browser, “draft” means that it hasn’t been edited for formatting, hasn’t had corresponding Fortran programs added, the text content hasn’t been enhanced, etc. Draft texts are extracted from the corresponding Tweet using the Twitter API.