S T R U C T O R I Z E R - User Guide
Elements > WHILE loop

A WHILE loop repeatedly executes a sequence of instructions — called its body — while a given Boolean condition holds. The logical condition is an entry condition i.e. it is tested each time before the body is going to be executed. If the condition expression is false on entering the loop element (the first time) then the loop body will not be executed at all.

The text to be filled in on adding a WHILE element is a Boolean expression, i.e. the logical condition. This may be a comparison, a variable with Boolean content, or several conditions combined by logical operators (see more details under IF statement). Please note:
The default text can be modified under Preferences › Structures.

This is how you add a WHILE loop to your diagram:

1. Click on the WHILE loop symbol in the toolbar (having selected the element, after which the WHILE loop is to be inserted):

Select the WHILE-Loop
 
2. Write a condition (a Boolean expression) into the text field:

Edit the WHILE-Loop 

3. Add instructions (i.e. the actions to be repeated while the condition is being true — it may of course also be elements of any other kind) into the loop body:

Add an instruction in the WHILE-Loop 

(The little red triangle in the loop element as shown above is just to draw your attention to a related Analyser warning in the Report list at the bottom. By the way, this warning is an important observation: Once you enter the loop, you will not ever have a chance to get out of it if the body does not contain an instruction with a possible impact on the condition, i.e., if none of the variables in the condition gets modified by an instruction within the loop body then you are caught forever! So you will see this warning with any new loop since its body is initially empty.)

4. If you want more than one instruction executed then just add them after or before the first one:

 Add an instruction After the first in the WHILE-Loop

5. If you want to add further instructions after the entire WHILE-Loop then you must select the loop head first:

 Add an instruction after the WHILE loop

6. This is what the finished version looks like:

 Completed WHILE loop

Download this Demo

Download other Demo (Newton's square root)