next up previous contents
Next: Examples of Loop Counts Up: Control Flow Previous: Named and Nested Loops

Indexed DO Loops

Loops can be written which cycle a fixed number of times.

The syntax is as follows,

 
DO  tex2html_wrap_inline43037  DO-var  tex2html_wrap_inline43039 = tex2html_wrap_inline43037  expr1  tex2html_wrap_inline43039 , tex2html_wrap_inline43037  expr2  tex2html_wrap_inline43039  [ , tex2html_wrap_inline43037  expr3  tex2html_wrap_inline43039  ]
  
		  tex2html_wrap_inline43037  exec-stmts  tex2html_wrap_inline43039 

END DO

For example,

    DO i1 = 1, 100, 1
      ...
    END DO

The number of iterations, which is evaluated before execution of the loop begins, is calculated as

 
MAX(INT(( tex2html_wrap_inline43037  expr2  tex2html_wrap_inline43039 - tex2html_wrap_inline43037  expr1  tex2html_wrap_inline43039 + tex2html_wrap_inline43037  expr3  tex2html_wrap_inline43039 )/ tex2html_wrap_inline43037  expr3  tex2html_wrap_inline43039 ),0)

If this is zero or negative then the loop is not executed.

If tex2html_wrap_inline43037  expr3 tex2html_wrap_inline43039 is absent it is assumed to be equal to 1.

For more information, click here gif


next up previous contents
Next: Examples of Loop Counts Up: Control Flow Previous: Named and Nested Loops

Adam Marshall ©University of Liverpool, 1996
Fri Dec 6 18:56:08 GMT 1996
Not for commercial use.