CS 455 Lecture Notes

Week Two, Thursday: Control Structures

Homework Two

Exercises 2.33, 2.35, and 2.36 in DD (page 136). Due in class Thursday, week 4. Also see the first project requirements on the Assignments page.

Transfer of Control

Source code files are sequences of characters. Statements are delimited by semicolons. Blocks of statements are grouped by curly braces. Statements are executed in the order they are written unless control is explicitly transferred by a control structure.

Sequential execution is easy to understand. Control structures add complexity to the task of understanding code and should be used carefully. The goto statement is one way of indescriminately transferring control and should be generally avoided. Educators have been fairly successful in generating awareness of this issue and many students as a result have never seen the goto statement used.

Flow Charts

The "flow" of control in a program can be diagrammed using block and diamond symbols to represent statement blocks and decisions, respectively. A graphical view of a program can aid in understanding code.

Selection Structures

Repetition Structures

Formulating Algorithms: Case Study 1

Counter-Controlled Repetition: fig02_07.cpp (see text).

Top-down stepwise refinement: fig02_09.cpp.

Assignment Operators

Examples of Using for

Sum the even integers. See fig02_20.cpp.


This page established September 7, 1999; last updated September 8, 1999.