Skip to main content

This is documentation for Caché & Ensemble.

For information on converting to InterSystems IRIS, see the InterSystems IRIS Adoption Guide and the InterSystems IRIS In-Place Conversion Guide, both available on the WRC Distributions page (login required).

Previous sectionNext section


Executes a series of statements as long as a given condition is true.


While condition


The While...Wend statement syntax has these parts:

conditions Expression that evaluates to True or False.
statements One or more statements executed while condition is True.


If condition is True, all statements in statements are executed until the Wend statement is encountered. Control then returns to the While statement and condition is again checked. If condition is still True, the process is repeated. If it is not True, execution resumes with the statement following the Wend statement.

While...Wend loops can be nested to any level. Each Wend matches the most recent While.


The following example illustrates use of the While...Wend statement:

Dim Counter
Counter = 0                ' Initialize variable.
While Counter < 20         ' Test value of Counter.
   Counter = Counter + 1   ' Increment Counter.
   Print Counter
Wend                       ' End While loop when Counter > 19.
Copy code to clipboard


The Do...Loop statement provides a more structured and flexible way to perform looping.

See Also