News for hackers. Stuff that matters.
Re:Tom Duff: Reading Code From Top to Bottom (1999) by barrkel on Sunday June 05, 2011 @01:25AM (#2621388)
On the topic of loops which end in a break ("Most egregious is the loop whose last statement is break;!"): this can be useful for avoiding contorted control flow when you have a switch statement inside the loop. Instead of coding:

    cont = 1;
    while (cont)
    {
        foo = bar();
        switch (foo)
        {
            case 0:
                cont = 0;
                break;
            default:
                // other work
                break;
        }
    }
You can do this instead:

    for (;;)
    {
        foo = bar();
        switch (foo)
        {
            case 0:
                break;
            default:
                // other work
                continue;
        }
        break;
    }
IMO the idiom, once you're used to it, reads better.

(Yes, I know you can reduce the lines further e.g. putting foo=bar() into the for statement, but it's the multi-level break I'm focused on here.)

Re:Tom Duff: Reading Code From Top to Bottom (1999) by ch on Sunday June 05, 2011 @08:33AM (#2621889)
Why not:

    while( (foo = bar()) != 0 )
    {
        /* other work */
    }
Or even simpler (since 'foo' serves no real purpose in the example):

    while( bar() )
    {
        /* other work */
    }