Help needed with using continue in loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • lyle777
    New Member
    • Apr 2010
    • 8

    Help needed with using continue in loop

    I need help with using continue in my loop.
    they say that when using continue in the loop that is nested,
    depending on the condition of the continue statement, execution
    should jump to the original loop statement and i am having trouble
    doing that........... please refere to the code below:

    Code:
    #include <iostream>
    using namespace std;
    int main()
    {
        int x, y;
        
        for(x=0; x>=-50000; x--) { 
    
                 cout << x << "\n";
    
                 if(y>10000) continue;    // my continue statement says that the loop    below should stop at 10000, but it doesnt, it continues all the way to 20000
    
                 for(y=0; y<20000; y++) {     // this 
    
                 cout << y << "\n";
                 }
        }
        
        
        cin.get();
        return 0;
    }
  • Banfa
    Recognized Expert Expert
    • Feb 2006
    • 9067

    #2
    You have not understood how continue works

    Read a reference source

    Comment

    • whodgson
      Contributor
      • Jan 2007
      • 542

      #3
      In the body of your first loop you talk about the value of variable y which has not yet been initialized.'co ntinue' refers to the loop in whose body it resides. Not the next loop.

      Comment

      Working...