C Definition
Not Applicable
Pascal Definition
Not Applicable
Description
The If Else block examines a condition and performs the first enclosed block list if a condition is true and an alternative second enclosed block list if the condition is false. One, and only one, of the two block lists will be performed. Conditional blocks can be nested to create case statements
confirming that at least one case has been identified.
Escapes
The If Else block does not produce any escapes.
Examples
This list of blocks is started when the start switch is closed. The forward switch is checked and if found to be "on" the drive motor moves in the positive direction. Otherwise it moves in the negative direction.
This list of blocks counts the value of coins inserted into a machine and notices if a coin is not a recognized type. This procedure will continue looping until 25 cents have been inserted. If the coin is not recognized a message is shown and an exception is generated.
Note that there is consideration for the detection signals to have long durations and "switch bounce" character. Consider the "penny" case. After detecting the penny there is 50 millisecond delay to insure that the mechanical switch is no longer bouncing and producing an unstable signal. Then the block list
waits for the signal to become inactive. If this waiting did not occur a long signal would produce numerous increments of the "Cents" variable since the program would loop around, find the penny detector still on, and increment "Cents". At the end of the list is a 50 millisecond delay to debounce the signal turning
off.
Related Topics
If
While
Repeat Until