Computer Science · Ch 4 — Introduction to Problem Solving
Sequence
4.5.1
Sequence
Look back at Examples 4.3 (sum of two numbers) and 4.4 (area and perimeter of a rectangle): in both, the statements execute one after another, from the first line to the last, with nothing skipped and nothing repeated. Algorithms in which all the steps are executed one after the other are said to execute in sequence. Sequence is the simplest possible flow of control — the flowchart of such an algorithm is a single straight chain of boxes with no diamonds and no loop-back arrows.
Real problems, however, do not always fit a straight line. An algorithm may need to:
- perform some routine task repeatedly, over and over, or
- behave differently depending on the outcomes of previous steps. …