WHILE ... DO

From InterBase

Go Up to Procedures and Triggers


Performs the statement or block following DO as long as the specified condition is TRUE. Available in triggers and stored procedures.

WHILE (<condition>) DO 
<<compound_statement>>
Argument Description

<condition>

Boolean expression tested before each execution of the statement or block following DO

<compound_statement>

Statement or block executed as long as <condition> is TRUE

Description: WHILE DO is a looping statement that repeats a statement or block of statements as long as a condition is true. The condition is tested at the start of each loop.

Example: The following procedure, from an isql script, uses a WHILE DO loop to compute the sum of all integers from one up to the input parameter:

CREATE PROCEDURE SUM_INT (I INTEGER) RETURNS (S INTEGER)
AS
BEGIN
S = 0;
WHILE (I > 0) DO
BEGIN
S = S + I;
I = I - 1;
END
END;

If this procedure is called from isql with the command:

EXECUTE PROCEDURE SUM_INT 4;

then the results will be:

S
==========
10

See Also

Advance To: