This functionality does not run in MATLAB.
while - end_while represents a loop that
evaluates its body while a specified condition holds true.
evaluated before the body is executed for the first time. If
the loop is entered and
condition evaluates to
In contrast to the
while loop, the body of
repeat loop is always evaluated at least once.
The body may consist of any number of statements which must
be separated either by a colon
: or a semicolon
Only the last evaluated result inside the body (the return value of
the loop) is printed on the screen. Use
end_while may be replaced by
The imperative form
while - end_while is
equivalent to corresponding call of the function
In most cases, the imperative form should be preferred because it
leads to simpler code.
is often a more elegant notation for loops.
_while is a function of the system kernel.
Intermediate results of statements within a
are not printed to the screen:
i := 1: s := 0: while i < 3 do s := s + i; i := i + 1; end_while
Above, only the return value of the loop is displayed. Use
i := 1: s := 0: while i < 3 do print("intermediate sum" = s); s := s + i; i := i + 1; s end_while
delete i, s:
A simple example is given, how a
can be expressed via an equivalent
For other examples, this may be more complicated and additional initializations
of variables may be needed:
i := 1: repeat print(i); i := i + 1; until i = 3 end:
i := 1: while i < 3 do print(i); i := i + 1; end:
condition := UNKNOWN: while not condition do print(Condition = condition); condition := TRUE; end_while:
Error: The Boolean 'TRUE' or 'FALSE' is expected. [while]
To avoid this error, change the stopping criterion to
condition := UNKNOWN: while condition <> TRUE do print(Condition = condition); condition := TRUE; end_while:
We demonstrate the correspondence between the functional and
the imperative form of the
hold(_repeat((statement1; statement2), condition))
repeat statement1; statement2 until condition end_repeat
hold(_while(condition, (statement1; statement2)))
while condition do statement1; statement2 end_while
The body of the loop: an arbitrary sequence of statements
Value of the last command executed in the body of the loop.
If no command was executed, the value
NIL is returned. If the body of a
is not evaluated due to a false condition, the void object of type