Controlling Flowchart Execution with Boolean Expressions

The diamond  symbol is used for decision making, either in a selection or loop structure.  The programmer enters in the diamond an expression that evaluates to Yes (True) or No (False). Such expressions are formally referred to as Boolean expressions. Based on the result of the expression in the diamond, control of the program will branch either left (Yes, or True) or right (No, or False). In the case of a diamond controlling exit from a loop, a Yes or True value results in an exit from the loop, while a No or False value causes control to continue in the loop and eventually to the top of the loop again.

 

The most common Yes/No (True/False) expressions are programmed by comparing two numeric expressions using one of the operators below:

 

= Equal True if the compared items are equal

/=

Not Equal

True if the compared items are not equal

!=

Not Equal

True if the compared items are not equal

> Greater Than True if the expression on the left is greater than the expression on the right
< Less Than True if the expression on the left is less than the expression on the right
>= Greater Than or Equal True if the expression on the left is greater than or equal to the expression on the right
<= Less Than or Equal True if the expression on the left is less than or equal to the expression on the right

 

Some examples of numeric comparisons follow:

 

count = 10

count mod 7 != 0

x > maximum

 

Boolean Operators

 

In addition, Boolean expressions can be combined using the AND, OR, XOR and NOT Boolean operators to formulate arbitrarily complex logical decisions. Some examples include:

 

n >= 1 and n <= 10

n < 1 or n > 10

 

The first example is true if n is BOTH greater than or equal to 1 AND less than or equal to 10. The second is true if EITHER n is less than 1 OR n is greater than 10.  

 

The XOR and NOT Boolean operators are rarely used.  

expression1 XOR expression2 is true when either expression1 or expression2 is true, but not both.

NOT expression is true when expression is false and false when expression is true.

 

While the examples above are numeric, the same comparison operators can be used for comparing string expressions.

 

Boolean Functions

 

Finally, some functions  return a value of true or false; these can also be used where ever a  Boolean expression is required.  Some examples of these are:

 

Key_Hit

Is_Open

Mouse_Button_Pressed(Left_Button)