ABSTRACT

We have already used the flow of control statements if and else extensively. In this chapter we will learn the other control flow statements provided by C++.

4.1 while loops There are three main ways to perform a task repeatedly in C++: for

loops, while loops, and do-while loops. The easiest to understand is a while loop. void␣launchRocket ()␣{

int␣count␣=␣10; while␣(count >0)␣{

cout␣<<␣count; cout␣<<␣"\n"; count --;

} cout␣<<␣"Blast␣off!\n";

}

To see what this code does, just call the launchRocket function from the main function.