On 30.04.2012 7:45, H. S. Teoh wrote:
On Sun, Apr 29, 2012 at 04:40:37PM +0200, Jacob Carlborg wrote:
[snip]
So you might say, OK, just write this then:

        for(;;) {
                auto line = nextLine();
                if (eof())
                        break;
                processLine(line);
        }

Well, finally you have something sane. The loop condition now correctly
appears in the middle of the loop body, which is where it should've been
all along. Only problem is, writing for(;;) is misleading, because
you're not looping indefinitely, there's precisely one exit condition.
Conveying intent is very important in writing good code, and this code
breaks that principle.

So really, what is needed is a sane looping construct that unifies while
loops, do-loops, and exit-in-the-middle loops. Something like this:

        loop {
                // first part of loop body
        } exitWhen(!loopCondition) {
                // second part of loop body
        }


You'd love PL/SQL. :)

--
Dmitry Olshansky

Reply via email to