
 |
![]() |
|
|
|
|
 |
The continue Statement
Now that we have covered the break statement we should cover the continue statement. The continue statement does the same thing as the break statement except that instead of terminating the loop, it goes back to the beginning of the loop's block to begin the next iteration (loop).
Here is an example that uses both continue and break:
 | |  | | | #include <iostream.h>
int main()
{
int n = 0;
for(;;)
{
cout << "Enter a number: ";
cin >> n;
if(n == 0) break;
else
continue;
}
cout <<"You just typed in 0! and it called the break statement!";
return 0;
} |
|  |
|
This program first creates a variable to accept the number, and I created a infinite loop, but I included the break and the continue statement. If the number the user entered is 0 then it goes to break else it continues and iterates again.
Please Rate this Code:
|
|
|
|
|
|
|