Structured Programming  «Prev  Next»
Lesson 6 Decision
Objective Describe the decision construct.

Decision Construct in Procedural Programming

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.

Decision construct allows us to modify the straight sequential flow of execution of a program
Decision construct allows us to modify the straight sequential flow of execution of a program

[1]Decision: Control flow construct in which a task is performed conditionally. Also referred to as selection.