Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DO WHILE and DO UNTIL
#1
Here you are my first two cents for the wishing well:

Now the DO-LOOP syntax is:

Quote:Do
[ statement block ]
Loop [ { Until | While } condition ]

I miss the following variant, allowed in FreeBASIC, Beta Basic and others:

Quote:Do [ { Until | While } condition ]
[ statement block ]
Loop

I think it's nice and clear to use just one loop structure and simply move the conditions. In fact the (less elegant, in my opinion) WHILE-WHILE END structure would be redundant (though it exists in FreeBASIC too).
Reply
#2
programandala.net Wrote:Here you are my first two cents for the wishing well:

Now the DO-LOOP syntax is:

Quote:Do
[ statement block ]
Loop [ { Until | While } condition ]

I miss the following variant, allowed in FreeBASIC, Beta Basic and others:

Quote:Do [ { Until | While } condition ]
[ statement block ]
Loop

I think it's nice and clear to use just one loop structure and simply move the conditions. In fact the (less elegant, in my opinion) WHILE-WHILE END structure would be redundant (though it exists in FreeBASIC too).
I didn't know DO UNTIL... LOOP was allowed in VB, since UNTIL usually is supposed to be at the end. Those constructions are not supported.
DO WHILE...LOOP can be implemented as WHILE ... END WHILE or WHILE ... WEND.
Reply
#3
boriel Wrote:I didn't know DO UNTIL... LOOP was allowed in VB, since UNTIL usually is supposed to be at the end.

The DO...LOOP in FreeBASIC allows every possible combination. It's simple, logical and versatile: UNTIL exits when the condition is true, and WHILE exits when the condition is false; their position (after DO or after LOOP) decides whether the first loop will always be executed or not. That feature is what ZX Basic lacks: In ZX Basic the commands inside DO...LOOP always will be executed at least once, unless a surrounding IF...END IF is used.

boriel Wrote:DO WHILE...LOOP can be implemented as WHILE ... END WHILE or WHILE ... WEND.

Of course. I suspect WHILE...END WHILe was added to FreeBASIC for compatibility with QBasic, because it's not needed, but I don't know.

Beta Basic provides the same DO...LOOP than FreeBASIC but no redundant WHILE...END WHILE.
Reply
#4
programandala.net Wrote:
boriel Wrote:I didn't know DO UNTIL... LOOP was allowed in VB, since UNTIL usually is supposed to be at the end.

The DO...LOOP in FreeBASIC allows every possible combination. It's simple, logical and versatile: UNTIL exits when the condition is true, and WHILE exits when the condition is false; their position (after DO or after LOOP) decides whether the first loop will always be executed or not. That feature is what ZX Basic lacks: In ZX Basic the commands inside DO...LOOP always will be executed at least once, unless a surrounding IF...END IF is used.

boriel Wrote:DO WHILE...LOOP can be implemented as WHILE ... END WHILE or WHILE ... WEND.
Of course. I suspect WHILE...END WHILe was added to FreeBASIC for compatibility with QBasic, because it's not needed, but I don't know.

Beta Basic provides the same DO...LOOP than FreeBASIC but no redundant WHILE...END WHILE.
Don't know about those BASIC flavours, but WHILE construct is a standard among many BASICs, C, PASCAL, Python etc... and always used to Repeat 0 or more times whilst DO ... WHILE, UNTIL, LOOPS etc... are used for Repeating 1 or more times (1 guaranteed even if initial condition fails). So WHILE is not "redundant" to me, but DO WHILE.

Also ZX BASIC support DO: ... : LOOP (which repeats forever). This is equivalent to for (;Wink in C or While(True) in many other languages (use it instead of While(1) whenever possible as it's optimized).

Anyway, I will add support for FreeBasic DO...LOOP implementation to maintain compatibility, since this easies the portability between ZX BASIC and FreeBasic. :roll:
Reply
#5
boriel Wrote:So WHILE is not "redundant" to me, but DO WHILE.

You're right: WHILE...END WHILE is more common. I said it's redundant only because a versatile DO...LOOP makes it unnecessary. But I'm not suggesting to remove it Smile

boriel Wrote:Also ZX BASIC support DO: ... : LOOP (which repeats forever).

Yes. By the way, I've just discovered that Beta Basic supports even this:

Code:
do while condition
...
loop until condition

It seems quite useful. Anyway I guess it's easier for the Beta Basic interpreter to let that a double condition than to forbid it. What do you think about letting both conditions in ZX Basic?

Beta Basic lacks END IF, so IFs cannot spread on several lines. But this trick can be used instead:

Code:
do while condition
...
loop until 1

boriel Wrote:Anyway, I will add support for FreeBasic DO...LOOP implementation to maintain compatibility, since this easies the portability between ZX BASIC and FreeBasic. :roll:

Great. The backward compatibility with Sinclair Basic and the forward compatibility with FreeBASIC make ZX Basic quite promising!
Reply
#6
Well, you already know, but for the new comers: Current version of ZX BASIC (1.2.6) already implements this.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)