Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
DO WHILE and DO UNTIL
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)