Iteration Using while-Statements


When using the for-loop for iteration you must be able to express the range of values over which the iteration variable should iterate in a
closed form such as an iteration expression. For cases where this is not feasible there is also a while-loop iteration construct in Modelica where the termination condition is just a Boolean expression and the range of iteration values need not be expressed in closed form as an expression. You need to declare the iteration variable separately, as well as handling the increment or decrement of this variable yourself.

The example class
SumSeries shows the while-loop construct used for summing a serries of exponential terms until the loop condition is violated (the terms become smaller than eps). In this case it would be quite impractical to use a for-loop.



1 Simulation of SumSeries