This article will cover the syntax of the ‘do… loop’ control script statement

This is an iterative statement that requires logical criteria. The code inside the loop will run until the conditions are met. 

Statement syntax

Do [ ( while | until ) condition ] [statements]
[exit do [ ( when | unless ) condition ] [statements]
Loop [ ( while | until ) condition ]



While | Until

These are logical clauses. Note that while or until can only appear in the statement once: either after ‘Do’ or after ‘Loop’. Only one of them can be used.

Condition

These are logical expressions that will be evaluated during each loop cycle. They must evaluate to True or False.

Statements

These are the statements to be executed while the control is looping.

Exit do

An ‘exit do’ clause forces the loop to stop. The script execution will move to the first statement after the loop statement.

When | Unless

These are suffixes that can only be used with the ‘exit do’ clause. Using these suffixes makes the ‘exit do’ a conditional clause.

Example

This is an example of a simple loop statement that creates a calendar consisting of a daily date for the whole of 2021.

Set a = '01/01/2021';
Do Until a > '31/12/2021'
CALENDAR:
LOAD * INLINE [
     Date,
     $(a)
     ];
Let a = Date(a+1,'DD/MM/YYYY');
Loop

Result

As a result, a calendar table is created with a single date field. The field contains 365 rows, one for each day of the year.