FOR ... DO

Top  Previous  Next

Use for a looping a fixed number of iterations.

 

Syntax

<for_do_loop> ::=

  FOR varname = <start> TO <end> 

  DO <compound_statement>

 

<compound_statement> ::= {<block> | <statement>}

 

The FOR ... DO statement is used for implementing loops for a fixed number of iterations. Both <start> and <end> should be integer expressions that result in a fixed value. The (implicit) variable used for iterating will be incremented automatically.

 

The loop can be broken without evaluating the condition with a LEAVE statement or exited with a EXIT or RETURN statement. The next iteration can be forced using a CONTINUE statement.

 

See Also

REPEAT ... UNTIL loop
WHILE ... DO loop

 

Example

EXECUTE UDSBLOCK

AS

BEGIN

  FOR i = 1 TO 10

  DO BEGIN

       IF (Math.Mod(i, 2) = 0) /* check for even numbers, skip the loop if even */

       THEN CONTINUE;

       ELSE BEGIN

              /* do stuff */

            END

     END

END