Sams Teach Yourself C++ in 21 Days
The Roots of Looping:goto.......................................................................... In the primitive days of ear ...
More on Program Flow 177 7 of gotostatements has caused tangled, miserable, impossible-to-read programs known as “spaghetti code ...
counter: 1 counter: 2 counter: 3 counter: 4 counter: 5 Complete. Counter: 5. This simple program demonstrates the fundamentals o ...
More on Program Flow 179 7 Exploring More Complicated whileStatements............................................ The condition ...
On lines 12–15, the numbers are entered. Line 20 sets up a whileloop, which will con- tinue only as long as two conditions are m ...
More on Program Flow 181 7 LISTING7.4 breakand continue 1: // Listing 7.4 - Demonstrates break and continue 2: #include <iost ...
Enter a small number: 2 Enter a large number: 20 Enter a skip number: 4 Enter a target number: 6 skipping on 4 skipping on 8 Sma ...
More on Program Flow 183 7 Examining while (true)Loops.................................................................... The c ...
whether counterhas gone past 10. If it hasn’t, the whileloop iterates. If counteris greater than 10, the break on line 13 ends t ...
More on Program Flow 185 7 7: int main() 8: { 9: int counter; 10: std::cout << “How many hellos?: “; 11: std::cin >> ...
Using do...while................................................................................................ The do...whilel ...
More on Program Flow 187 7 The do...whileStatement The syntax for the do...whilestatement is as follows: do statement while (con ...
LISTING7.8 whileReexamined 1: // Listing 7.8 2: // Looping with while 3: 4: #include <iostream> 5: 6: int main() 7: { 8: i ...
More on Program Flow 189 7 LISTING7.9 Demonstrating the forLoop 1: // Listing 7.9 2: // Looping with for 3: 4: #include <iost ...
Advanced forLoops ...................................................................................... forstatements are power ...
More on Program Flow 191 7 Null Statements in forLoops Any or all the statements in a forloop can be left out. To accomplish thi ...
LISTING7.12 Illustrating an Empty forLoop Statement 1: //Listing 7.12 illustrating 2: //empty for loop statement 3: 4: #include ...
More on Program Flow 193 7 LISTING7.13 Illustrates the Null Statement in a forLoop 1: //Listing 7.13 2: //Demonstrates null stat ...
8: int rows, columns; 9: char theChar; 10: cout << “How many rows? “; 11: cin >> rows; 12: cout << “How many c ...
More on Program Flow 195 7 The important idea here is that by using a nested loop, the inner loop is executed for each iteration ...
«
6
7
8
9
10
11
12
13
14
15
»
Free download pdf