Switching logic consists of two components - a condition and a command depending on the result of the condition test. Read A, B If A is less than B BIG = B else BIG = A SMALL = B
The computer can determine the truth value of a statement involving one of six mathematical relations symbolized in the table below:
Symbol & Meaning
= Equals
!= Not Equal
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
example
and SALES = 10000, then:
Is A == B? No
Is B > A? Yes
Is K <= 25? Yes
Is SALES >= 5000.00? Yes
With each question, the computer can be programmed to take a different course of action depending on the answer.
A step in an algorithm that leads to more than one possible continuation is called a decision.
In flowcharting, the diamond-shaped symbol is used to indicate a decision. The question is placed inside the symbol, and each alternative answer to the question is used to label the exit arrow which leads to the appropriate next step of the algorithm.
The example below shows the flowchart for a program that reads two numbers and displays the numbers read in decreasing order: