While Do

Navigation:  Language Reference > Statements >

While Do

Previous pageReturn to chapter overviewNext page

Syntax

code

 while condition do

         equation;

         equation;

         ....

 end;

Description

The while statement is designed to execute equation(s) repeatedly, as long as the condition is true. The condition is evaluated before the equations are executed.

 

It is the user's responsibility to guarantee that the execution of the while statement finishes by making the condition become false at a certain time.

Example

variables

 real i,y[3];

initialequations

 y = 0;

code // Use code to ensure sequential execution

 i = 1;

 while i <= rows(y) do

         // executed 3 times for each model calculate:

         // y[1] and y[2] and y[3] are filled

         y[i] = sin(time) * i;

         // i is incremented to guarantee a stop of the loop

         i = i + 1;

 end;

Limitations

1.The output of the condition must be a boolean. If the boolean does not become false, the loop never ends! There are no limitations to the number of equations that can be used within the while statement.
2.Equations within an while statement have to be written in the correct order of execution, i.e. they are not rewritten into a causal form but executed sequentially.