c++ continue versus break

前端 未结 6 1029
抹茶落季
抹茶落季 2020-12-16 15:02

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

for(int i = 0; i < count; ++i)
 {
     // statement1                                            


        
6条回答
  •  旧巷少年郎
    2020-12-16 15:34

    continue ends the current iteration, virtually it is the same as:

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

    break exits the loop:

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

提交回复
热议问题