S T R U C T O R I Z E R - User Guide
Elements > IF statement

An element of type IF statement represents an alternative in the control flow. It is used at a decision point where the algorithm must take one of two different ways. The IF statement comprises the condition and both emerging paths. After having passed the selected path the control flow will continue below the IF element.

The text of the IF element is to contain the logical condition. It may be represented by any boolean expression, i.e. an expression that evaluates either to true or to false. If the value computes to true then the left branch will be taken, otherwise the right branch.

Please note:
The labels for the "TRUE" and "FALSE" branch in the graphical presentation can be modified in Structure Preferences (menu item "Preferences => Structures").

This is how you add an IF statement to your diagram:

1. Select the element at the target position of the intended IF Startement, then click on the IF statement button in the menu:

Select the IF-Statement
 
2. Insert a condition

When the element editor opens then the text field will contain a default string, which is configurable in the Structure Preferences. Replace this default string by the actual condition. This may be a comparison, a variable with boolean content, or several conditions combined by logical operators.

Accepted logical operators are and (or &&), or (or ||), not (or !), and xor (or ^), where the latter stands for exclusive or (A xor B is true if exactly one of the conditions A or B is true).

If one of the two branches is meant to remain empty (i.e. you are just going to create a "conditioned instruction") then formulate the condition in such a way that the non-empty branch is the "TRUE" branch. (If you accidently did otherwise you may simply swap branches and negate the condition by means of transmutation.)

Edit the IF-Statement 

3. Add the elements to be executed depending on the condition, e.g. Instructions, to the respective branches (see Diagram/Add elements):

Add an instruction in the IF-Statement 

4. If you want to have more than one instruction executed in a branch then add them after or before the first one (i.e. make sure to have selected an element of the branch when inserting or appending another one): Add an instruction after the first one in the IF-Statement

5. If you want to add further elements after the entire IF statement (no matter, which branch was chosen and executed, the control flow will continue with the element following the IF statement) you must select its head first:

Add an instruction after the IF statement

6. This is what the finished version could look like (note that neither the INPUT instruction nor the yellow-coloured OUTPUT instruction is part of the alternative):

Completed IF statement

Download Demo