DO/END_DO: Using Do-Loops in Procedures



The DO/END_DO commands enable you set set up repeatable groups of commands within the procedure buffer. The VISTA DO-LOOP is very similar to the Fortran DO-LOOP.

The variable 'var' is initially set equal to the starting value N1. When the END_DO statement is encountered the value is changed by an amount equal to N3. The value of N3 can be either positive or negative. If N3 is positive then the looping terminates when N1 becomes greater than N2. If N3 is negative then looping terminates when N1 becomes less than N2. If N3 is not specified then it defaults to +1.0 if N2 is greater than N1 or to -1.0 if N2 is less than N1.

N1, N2, and N3 can all be arithmetic expressions as described in the SET command. The value of 'var' can be changed within the loop without affecting the do-loop operation. However, VISTA will reset 'var' to its appropriate loop value at the beginning of each loop.

The underline is required in END_DO because VISTA requires commands to be one word long. Up to 20 do-loops can be nested. Do-loops are recognized only within procedures. The GOTO command can be used to jump out of a DO loop, but VISTA will not permit jumping into one. Further, DO loops must contain or be contained completely within any IF blocks.

Examples:

  1.      DO I=1,3
            Any number of procedure lines.  These lines are executed 3 times.
         END_DO
    
  2.      DO Q=1,N
            Any number of procedure lines.  These lines are executed N times.
            Here N is a variable that has had its value set by the SET command.
         END_DO
    
  3.      DO B=D+I,N-J,-1
            Any number of procedure lines.  The counter
            decrements from D+I to N-J.
         END_DO