
6.10 Count-Controlled Loops Using for 343
Enter integer 1 > 23
Enter integer 2 > 12
Enter integer 3 > 10
Enter integer 4 > 11
Enter integer 5 > 15
The total is 71
6.10.3 Testing Techniques for for Loops
One of the most important tests for for loops is that the starting and ending
values of the loop variable are set correctly. For example, to execute a for
loop five times, we could set the initial value of the loop variable to 0 and
use the condition (
i < 5), or we could set the initial value of the loop vari-
able to 1 and use the condition (
i <= 5). Either of these for loop headers will
cause the loop to execute five times.
for ( int i = 0; i < 5; i++