While
Table of Contents
The iteration statement While executes a statement or statement block as long as the condition, mentioned in the While statement, is met.
Description
In the AI-Framework, the While statement has a condition, which is a Boolean expression returning TRUE or FALSE. As long as the expression returns true, the statements between braces { and } are being executed.
At any point within the While statement block, you can break out of the loop using the Break . You can step to the next iteration in the loop using the Continue .
C# example
A simple C# example of using for each shows the Fibonacci sequence.
int n = 0;
while (n < 10)
{
Console.WriteLine(n);
n++;
}
The variable n is initialised and set to zero. When entering the While loop, the Boolean expression n < 10 is TRUE. Therefore, the value of n is written and n is incremented with 1. When n reaches the value 10, the loop ends and the value 10 is not written.
AI-Framework example
In the following code example, While loops based on variable number.
number.Assign(0)
new While(number < 5)
{
AddToInvoiceLine(article),
number.Assign(number + 1)
}
The variable number is assigned the value zero on line 1 and incremented on line 5. As long as number is smaller than 5, the Method AddToInvoiceLine() is called.
> See also the similar Foreach statement.