4. Decisions¶
A decision is a yes/no question that sends the flow down one of two paths. In a flowchart, this is the diamond shape, with two arrows leaving it — one for each answer.
( Start )
|
< Is it raining? >
Yes / \ No
/ \
[ Take an umbrella ] [ Leave it home ]
\ /
\ /
( End )
The pseudocode version uses IF, THEN, and ELSE, with indenting to show what belongs to each branch:
IF it is raining THEN
Take an umbrella
ELSE
Leave it home
Try it
Draw a decision diamond for "Is it after 10pm?" with two branches, each ending in a different action. Write the matching IF / ELSE pseudocode.
Tip
Every decision diamond needs exactly two ways out — if you find yourself wanting a third arrow, you probably need two decisions instead of one.