January 2014
Intermediate to advanced
736 pages
70h 43m
English
The following examples show techniques for varying the control variable in a for statement. In each case, we write the appropriate for header. Note the change in the relational operator for loops that decrement the control variable to count downward.
a) Vary the control variable from 1 to 100 in increments of 1.
for ( int i = 1; i <= 100; ++i )
b) Vary the control variable from 100 to 1 in decrements of 1.
for ( int i = 100; i >= 1; --i )
c) Vary the control variable from 7 to 77 in increments of 7.
for ( int i = 7; i <= 77; i += 7 )
d) Vary the control variable from 20 to 2 in decrements of 2.
Read now
Unlock full access