August 2001
Beginner
482 pages
10h 52m
English
When programming while loops, you'll often find yourself setting up a starting condition, testing to see if the condition is true, and incrementing or otherwise changing a variable each time through the loop. Listing 6.7 demonstrates this.
0: // Listing 6.7
1: // Looping with while
2: #include <iostream>
3:
4: int main()
5: {
6: int counter = 0;
7:
8: while(counter < 5)
9: {
10: counter++;
11: std::cout << "Looping! ";
12: }
13:
14: std::cout << "\nCounter: " << counter << ".\n";
15: return 0;
16: }
|
Looping! Looping! Looping! Looping! Looping! counter: 5.
The condition is set on line 6: counter ... |
Read now
Unlock full access