Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Use goto

Name: Anonymous 2012-09-17 19:14

I'm using goto outside assembly and there's nothing you can do about it, meanwhile your jewish teachers gave your looping toys and forbid faster code for you.

Name: Anonymous 2012-09-17 23:45

>>12,13
This is a simple example, so the value may not be immediately evident. Consider the case where qux represents a non-trivial amount of code - do you really want to nest all of it inside the else? Doing that is arguably less readable than just using goto.

Multiple nested elses also don't deal well with cases where you need to do a bunch of things in order and then back them all out if something goes wrong, e.g.


int foo(int x)
{
    int status = 0;
   
    (void) bar(x);
   
    if (0 != baz(x)) {
        status = -1;
        goto out1;
    }
   
    if (0 != qux(x)) {
        status = -1;
        goto out2;
    }
   
    (void) xyzzy(x);
   
out2:
    unbaz(x);
out1:
    unbar(x);
   
    return status;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List