7. Flowcharts Positive Numbers

Selection is a control structure that allows a program to choose between different actions based on a condition.
It’s represented by IF…THEN…ELSE statements.
In simple terms: “If something is true, do this. Otherwise, do that.”
The pseudocode below checks to see whether a number is positive or not.
ALGORITHM positiveOrNot()

BEGIN
    INPUT number
    IF number > 0 THEN
        PRINT number + " is positive."
    ELSE
        PRINT number + " is not positive."
    ENDIF
END
The new shape in the flowchart (number > 0?), is for a decision, which tests a condition and answers True (Yes) or False (No).
These decisions are written on each branch line.
../_images/positive_or_not.png


Tasks

  1. What shape is used for a decision?

  2. In the pseudocode above, what keywords start and end the line that checks the number?

  3. In the pseudocode above, what keyword starts the code for the NO branch of the flowchart?

  4. In the pseudocode above, what keyword ends the code for the IF block?

What shape is used for a decision?

A diamond

In the pseudocode above, what keywords start and end the line that checks the number?

IF and THEN

In the pseudocode above, what keyword starts the code for the NO branch of the flowchart?

ELSE

In the pseudocode above, what keyword ends the code for the IF block?

ENDIF