OOPortal 





Structured Programming  «Prev  Next»
Lesson 6 Decision
Objective Describe the decision construct.
Most programs have statements that are to be executed only under certain conditions. The decision construct (also referred to as the selection construct) allows you to do this. For example, consider the following modified version of the GoForARide program:

Decision: Control flow construct in which a task is performed conditionally. Also referred to as selection.
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 flowchart