NCL Home > Documentation > Language


"do loops" in NCL are the same as those in Fortran except that the optional stride must always be positive. The components of the loop include the familiar identifier (do n...), a scalar start expression (do n=0...) , a scalar end expression (do n = 0, nfiles-1), and, optionally, a stride do n=0, nfiles-1,4). Note: there is a space between the "end" and the "do" in NCL: (end do)! Second note: remember that array indexing in NCL begins with a 0 instead of a 1.

NCL also accepts "do while" loops:

   i = 0
   do while(i.le.n)
   end do
There are two ways of breaking out of a loop. break causes the loop to abort and proceed to the statement after the end do statement, and continue causes the loop to proceed to the next iteration.

Since NCL is an interpreted language, it is best to avoid do loops as much as possible. They can cause considerable slow downs. Small loops should not be a problem.