Section 6.11. The continue Statement


6.11. The continue Statement

A continue statement causes the current iteration of the nearest enclosing loop to terminate. Execution resumes with the evaluation of the condition in the case of a while or do while statement. In a for loop, execution continues by evaluating the expression inside the for header.

For example, the following loop reads the standard input one word at a time. Only words that begin with an underscore will be processed. For any other value, we terminate the current iteration and get the next input:

      string inBuf;      while (cin >> inBuf && !inBuf.empty()) {              if (inBuf[0] != '_')                   continue; // get another input              // still here? process string ...      } 

A continue can appear only inside a for, while, or do while loop, including inside blocks nested inside such loops.

Exercises Section 6.11

Exercise 6.21:

Revise the program from the last exercise in Section 6.10 (p. 213) so that it looks only for duplicated words that start with an uppercase letter.




C++ Primer
C Primer Plus (5th Edition)
ISBN: 0672326965
EAN: 2147483647
Year: 2006
Pages: 223
Authors: Stephen Prata

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net