FAQ  •  Register  •  Login

DO WHILE and DO UNTIL

<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Sat May 22, 2010 2:31 pm

DO WHILE and DO UNTIL

Here you are my first two cents for the wishing well:

Now the DO-LOOP syntax is:

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


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

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).
<<

boriel

Site Admin

Posts: 1271

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat May 22, 2010 6:27 pm

Re: DO WHILE and DO UNTIL

programandala.net wrote:Here you are my first two cents for the wishing well:

Now the DO-LOOP syntax is:

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


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

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.
<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Sat May 22, 2010 6:52 pm

Re: DO WHILE and DO UNTIL

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.
<<

boriel

Site Admin

Posts: 1271

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sat May 22, 2010 9:21 pm

Re: DO WHILE and DO UNTIL

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 (;;) 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:
<<

programandala.net

Posts: 98

Joined: Fri Apr 09, 2010 12:50 am

Location: España/Hispanujo/Spain

Post Sat May 22, 2010 11:27 pm

Re: DO WHILE and DO UNTIL

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 :)

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!
<<

boriel

Site Admin

Posts: 1271

Joined: Wed Nov 01, 2006 6:18 pm

Location: Santa Cruz de Tenerife, Spain

Post Sun Jun 06, 2010 8:32 pm

Re: DO WHILE and DO UNTIL

Well, you already know, but for the new comers: Current version of ZX BASIC (1.2.6) already implements this.

Return to Wishlist

Who is online

Users browsing this forum: No registered users and 2 guests

cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by Vjacheslav Trushkin for Free Forums/DivisionCore.

phpBB SEO