How can i use a 'break' statement within a for-loop which continues form a specified label?
ex;
outer: for(int i = 0;i<[arABFBmatches count];i++){ for(int i = 0;i<[arABFBmatches count];i++){ // break _____; } }
How to break to outer?
The continue statement in Objective-C programming language works somewhat like the break statement. Instead of forcing termination, however, continue forces the next iteration of the loop to take place, skipping any code in between.
Hard to say from your question. I'd interpret it that you want to skip the rest of the iterations of the inner loop and continue the outer loop?
for (int i = 0; i < [arABFBmatches count]; i++) { for (int j = 0; j < [arABFBmatches count]; j++) { if (should_skip_rest) break; // let outer loop continue iterating } }
Note that I changed the name of your inner loop invariant; using i
in both is inviting insanity.
If you want to break from both loops, I wouldn't use a goto. I'd do:
BOOL allDoneNow = NO; for (int i = 0; i < [arABFBmatches count]; i++) { for (int j = 0; j < [arABFBmatches count]; j++) { if (should_skip_rest) { allDoneNow = YES; break; } } if (allDoneNow) break; }
Roughly:
for(int i = 0;i<[arABFBmatches count];i++){ for(int j = 0;j<[arABFBmatches count];j++){ // goto outer_done; } } outer_done:
Objective-C does not have labelled break.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With