Week 5 - Repetition and Loop Statements

During this week we cover Chapter 5 of Friedman & Koffman, in which we learn how to repeat a process many times. We will cover the three C++ loop control statements: while, for, and do-while. This will complete the three basic program control structures, being sequence, selection, and repetition.

The various relevant programs for this week have been loaded onto condor. After logging in, change directory to the week5 directory and list the various files as follows:

cd /home/condor/et181/week5
ls

Another common aspect of the for loop is its use in converting a series summation (Σ) into C++ code. Thus for example, the series summation:

could be represented by the following for loop:

int sum = 0;
for(int i = 1; i <= n; i++)
   sum = sum + i*i; // also: sum += i*i;

Note that before modifying or compiling any example in the week5 directory, you will first need to copy that example to your home directory, and return to your home directory as in the following example:

cp for_bottles.cpp ~
cd