c++ continue versus break

eugene picture eugene · Jun 16, 2011 · Viewed 30.4k times · Source

Which statement will be executed after "continue" or "break" ?

for(int i = 0; i < count; ++i)
 {
     // statement1                                                                                                                                                                                                                          
     for(int j = 0; j < count; ++j)
     {
         //statement2                                                                                                                                                                                                                       
         if(someTest)
             continue;
     }
     //statement3                                                                                                                                                                                                                           
 }

for(int i = 0; i < count; ++i)
 {   
     // statement1                                                                                                                                                                                                                          
     for(int j = 0; j < count; ++j)
     {   
         //statement2                                                                                                                                                                                                                       
         if(someTest)
             break;
     }
     //statement3                                                                                                                                                                                                                           
 }

Answer

Petar Ivanov picture Petar Ivanov · Jun 16, 2011

continue: ++j and then if j < count then statement2 otherwise statement3

break: statement3