Most programs have statements that are to be executed only under certain conditions. The
decision[1] construct (also referred to as the selection construct) allows you to do this. For example, consider the following modified version of the GoForARide program:
Put on cycling clothes
If the weather is cold
Put on a jacket
Put on tights
Go for a ride
Remove cycling clothes
Take a shower
In this program the statements:
Put on a jacket
Put on tights
are executed only when the weather is cold. This is indicated in the pseudocode by indenting these two statements beneath the decision statement:
If the weather is cold
In the next lesson we will look at the repetition construct.
Here is a flowchart for this program. Note how the decision construct allows us to modify the straight sequential flow of execution of a program.
Here is the equivalent PlantUML code that recreates the cycling flowchart you provided:
@startuml
start
:Put on cycling clothes;
if (Weather is cold?) then (Yes)
:Put on a jacket;
:Put on tights;
endif
:Go for a ride;
:Remove cycling clothes;
:Take a shower;
stop
@enduml
🛠 To render this:
- Use a PlantUML editor (e.g., PlantUML Live or PlantText).
- Paste the code in and click "Refresh" or "Render" to see the flowchart.