11.2 — Arrays (Part II)

Warning This lesson has been deprecated and replaced with the updated lessons in the latter half of chapter 17 (starting with lesson ). This lesson continues the discussion of arrays that began in lesson . Initializing fixed arrays Array elements are treated just like normal variables, and as such, they …

8.11 — Break and continue

Although you have already seen the break statement in the context of switch statements (), it deserves a fuller treatment since it can be used with other types of control flow statements as well. The causes a while loop, do-while loop, for loop, or switch statement to end, with execution …

8.10 — For statements

By far, the most utilized loop statement in C++ is the for-statement. The (also called a ) is preferred when we have an obvious loop variable because it lets us easily and concisely define, initialize, test, and change the value of loop variables. As of C++11, there are two different …

8.7 — Goto statements

The next kind of control flow statement we’ll cover is the unconditional jump. An unconditional jump causes execution to jump to another spot in the code. The term “unconditional” means the jump always happens (unlike an if-statement or switch-statement, where the jump only happens conditionally based on the result of …

8.5 — Switch statement basics

Although it is possible to chain many if-else-statements together, this is both difficult to read and inefficient. Consider the following program: #include <iostream> void printDigitName(int x) { if (x == 1) std::cout << “One”; else if (x == 2) std::cout << “Two”; else if (x == 3) std::cout << “Three”; …