Program Notes
Note that whereas the continue
statement causes the program in Listing 6.12 to skip the rest of the loop body, it doesn’t skip the loop update expression. In a for
loop, the continue
statement makes the program skip directly to the update expression and then to the test expression. For a while
loop, however, continue
makes the program go directly to the test expression. So any update expression in a while
loop body following the continue
would be skipped. In some cases, that could be a problem.
This program doesn’t have to use continue
. Instead, it could use this code:
if (line[i] == ' ') spaces++;
However, the continue
statement can make a program more readable when several statements follow the continue
. That way, you don’t ...
Get C++ Primer Plus now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.