| Store | Cart

No, loop-and-a-half! (Re: REPEAT... UNTIL ?)

From: Paul Svensson <p...@svensson.org>
Sun, 14 Jul 2002 09:36:47 +0000 (UTC)
bellman at lysator.liu.se (Thomas Bellman) writes:

>Greg Ewing <see_reply_address at something.invalid> wrote:>>> On the other hand, a situation that *is* very common is>> a loop-and-a-half, with the exit condition in the middle.>> So far, I've never seen *any* really good loop-and-a-half>> structure in any language, and I think Python has a chance>> to be truly innovative here.>>As others have already said, iterators can sometimes alleviate>this problem.>>And there is *one* language where I think the structure for>loop-and-a-half *is* good: Forth.  The syntax goes something>like

 (---)

Bourne Shell also has

        while
                foo
                bar
                gazonk ?
        do
                gurka
        done

>I *would* have liked that to be>>    repeat:>       part_1()>    while test_1():>       part_2()>    while test_2():>       part_3()>    while test_3():>       part_4()>>in Python, but that is unfortunately not compatible with the>current Python syntax. :-(

The problem is that there's no indication where the repeat: block ends.
If we should invent new syntax, I would limit it to the loop-and-a-half,
and keep "break" for multiple exit loops.

    repeat:
        part_1()
    while test_1():
        part_2()

This is unambigous to the compiler, but not could be confusing to humans,
specially if part_1() is large.  Adding more new keywords makes it clearer:

    repeat:
        part_1()
    until not test_1():
        part_2()

Or, inspired by Bourne, with no new keywordss at all (and even more cryptic):

    while:
        part_1()
        test_1():
            part_2()

I don't see anything like this happening anytime soon.

        /Paul

Recent Messages in this Thread
Rich Harkins Jul 12, 2002 01:52 pm
Andrew Clover Jul 15, 2002 09:47 am
Alexis Layton Jul 12, 2002 02:43 am
Andrew Clover Jul 12, 2002 09:47 am
Paul Svensson Jul 14, 2002 09:36 am
Messages in this thread