Summary

There are a number of different ways of causing a C++ program to loop. while loops check a condition, and if it is true, execute the statements in the body of the loop. do...while loops execute the body of the loop and then test the condition. for loops initialize a value and then test an expression. If expression is true, the body of the loop is executed, as is the final statement in the for header. Each subsequent time through the loop, the expression is tested again. The goto statement is generally avoided, because it causes an unconditional jump to a seemingly arbitrary location in the code, thus making source code difficult to understand and maintain. continue causes while, do...while, and for loops to start over, and break causes ...

Get Sams Teach Yourself C++ in 24 Hours, Third Edition 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.