Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ continue versus break

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                                                                                                                                                                                                                           
 }
like image 300
eugene Avatar asked Jun 16 '11 06:06

eugene


People also ask

What is difference between break and continue in C?

The primary difference between break and continue statement in C is that the break statement leads to an immediate exit of the innermost switch or enclosing loop. On the other hand, the continue statement begins the next iteration of the while, enclosing for, or do loop.

What is difference between break and continue?

Break statement stops the entire process of the loop. Continue statement only stops the current iteration of the loop. Break also terminates the remaining iterations. Continue doesn't terminate the next iterations; it resumes with the successive iterations.

Why we use break and continue statement?

The break statement is used to terminate the loop immediately. The continue statement is used to skip the current iteration of the loop. break keyword is used to indicate break statements in java programming. continue keyword is used to indicate continue statement in java programming.


1 Answers

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

break: statement3

like image 194
Petar Ivanov Avatar answered Oct 11 '22 10:10

Petar Ivanov