CopyPastor

Detecting plagiarism made easy.

Score: 0.8150812983512878; Reported for: String similarity Open both answers

Possible Plagiarism

Plagiarized on 2020-09-15
by Samaursa

Original Post

Original - Posted on 2013-06-12
by Deqing



            
Present in both answers; Present only in the new answer; Present only in the old answer;

Apart from what was pointed out in the comments, which is to force the value of `j`, you can use a lambda and call it inline. It's a bit ugly but does the job:
for( int i = 0 ; i < n ; i++ ){ [&]() { for( int j = 0 ; j < n ; j++ ){ if( condition ){ return } // some work being done work(); } }(); }
One nice way to break out of several nested loops is to refactor your code into a function:
void foo() { for(unsigned int i=0; i < 50; i++) { for(unsigned int j=0; j < 50; j++) { for(unsigned int k=0; k < 50; k++) { // If condition is true return; } } } }

        
Present in both answers; Present only in the new answer; Present only in the old answer;