Code About Us Tutorial


  Statements & Expression
    The while Statement
    The do ... while Statement
    The for Statement
    The break Statement
    The continue Statement
    The goto Statement
    The switch Statement
    Keywords
    Scope Resolution (::)
    Arithmatic Operators


   
 

Home > Statements & Expression > The continue Statement

November 30, 2009 2:14 am

   

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:


    Comments for: The continue Statement
Annonymouse User says:
The example given is slightly pointless since the program would perform exactly in the same way if we remove the continue statement. In my experience, the continue statement is best used to prevent the execution of tha last part of a loop-body (without terminating the loop) when a given condition occurs somewhere in the middle of the loop.

MoMad [big_mo_mine@yahoo.com] Posted: 31 times. says:
Thats right!! It would have been much better if there was more calculations after the input checking.




Add Comment:
Name:
Email:


 «5» THINKQUEST TEAM C0111571 © 2001. All Rights Reserved.