Breaking out of a nested loop

Started by
50 comments, last by ExErvus 7 years, 9 months ago

Just replace the for loops with if goto pairs so that goto won't look so lonely.


So...


int i = 0, j = 0;
    loop:
        if(i - 1 == j + 1)
            goto outer;
    ++j;
    if(j < 10)
        goto loop;
    ++i;
    if(i < 10)
        goto loop;

outer:
Seems pretty clean to me!

you have to set j back to zero tho else it does the job. Also this is how assembly would work

Bring more Pain
Advertisement

you have to set j back to zero tho else it does the job. Also this is how assembly would work


Oh crap! :unsure:

So... int i = 0, j = 0; loop: if(i - 1 == j + 1) goto outer; ++j; if(j < 10) goto loop; j = 0; ++i; if(i < 10) goto loop; outer: Seems pretty clean to me!

That looks terrifying

This topic is closed to new replies.

Advertisement