# Using "continue" (basic language problem)

• 09-06-2004
DominicTrix
Using "continue" (basic language problem)
If I have something like:
Code:

```for(int i=0; i<100; i++) {   for(int n=0; n<100; n++)   {       if(n==i)         continue;       ... // more stuff   }   ... // more stuff }```
Can I, with a single line of code, make the "continue;" skip to the end of the outer loop (i.e. rather than just the loop it's in).

dt
• 09-06-2004
alphaoide
Is not a single line, but...(Why you want a single-line solution anyway?)
Code:

```bool found = false; for ( int i = 0; i < 100; i++ ) {   for ( int n = 0; n < 100; n++)   {       if ( n == i ) {         found = true;         continue;       }       ... // stuff to skip   }       if ( found )         continue;   ... // more stuff to skip }```
Or lookup "goto", never used that before so don't know how to use it ;)
• 09-06-2004
DominicTrix
Many thanks. That's what I've been doing, but I was wondering if there was a slimmer way of doing it as it's in a seriously nested loop which needs to be as efficient as possible. A single line solution would be great and I seem to remember seeing one for break, so I figured there'd be one for continue. I'm probably imagining things though!

dt
• 09-06-2004
alphaoide
Well then lookup "goto", it'll be something like this
Code:

```for ( int i = 0; i < 100; i++ ) {   for ( int n = 0; n < 100; n++)   {       if ( n == i ) {         goto LABEL_A;       ... // stuff to skip   }     ... // more stuff to skip   LABEL_A }```
I don't know the exact construction. And note that the use of "goto" is a sensitive issue so I don't know if this one is one of the correct implementations of "goto"
• 09-06-2004
Prelude
>And note that the use of "goto" is a sensitive issue
You can say that again. The ignorant masses tend to drive controversy. ;)

>so I don't know if this one is one of the correct implementations of "goto"
That is one of the "acceptable" uses. But using goto feels inelegant; I would spend a few grey cells trying to restructure the program so that it's unnecessary.
• 09-06-2004
DominicTrix
Thankyou Alphaoid. I agree with Prelude though, and I've just stuck with what I've got and slimmed everything else down as much as possible (just bought Effective C++ so on a mission ;). I got the 3-4 second loop in question, down to around half a second. It's amazing what crap you can write when you write code ad lib and without real design!