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.
Tasks
What shape is used for a decision?
In the pseudocode above, what keywords start and end the line that checks the number?
In the pseudocode above, what keyword starts the code for the NO branch of the flowchart?
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