Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
While Not or Until in a DO/LOOP
#1
Whats the difference, or advantage, of using WHILE NOT or UNTIL in a DO/LOOP?

Such as:

Code:
DO WHILE NOT EOF(1)
   INPUT #1, a$
   PRINT a$
LOOP

or:

Code:
DO UNTIL EOF(1)
   INPUT #1, a$
   PRINT a$
LOOP

Also, I can never seem to remember, whats the difference between putting the test at the beginning or end of the loop?
Such as:

Code:
DO UNTIL EOF(1)
   INPUT #1, a$
   PRINT a$
LOOP

or:

Code:
DO
   INPUT #1, a$
   PRINT a$
LOOP UNTIL EOF(1)

Thanks all, Dex
Reply
#2
There is absolutly no difference Big Grin
Reply
#3
For all practical purposes the DO UNTIL, WHILE NOT... and so forth are the same, however if you are using the program as a counter of sorts it does make a difference. i;e,:

I = 10
PRINT "Starting Value of I = ";I
DO WHILE I < 10
I = I + 1
LOOP
PRINT "FINAL VALUE OF I = " I ( You'll end up with 10)

Compared with:

I = 10
PRINT "Starting Value of I = ";I
DO
I - I + 1
LOOP WHILE I < 10
PRINT " Ending Value of I = ";I ( You'll end up with 11)
So you see it can make a difference where you place the "comparison" value.
Just a little F.Y.I. Big Grin
adsherm
Reply
#4
Thanks folks, thats what I needed to know. Smile

Dex
Reply
#5
Just a simple way to remember, a while loop will be executed only after the condition is checked and is true. Where as a Do...Loop will be first executed and then the condition will be checked.

So if the condition is false at the begining of the loop, a do...loop is executed atleast once. But a while loop isnt executed at all. For example:
Code:
i% = 11
DO
   PRINT "executed do"
   i% = i% + 1
LOOP UNTIL i% >= 10

WHILE i% <= 10
   PRINT "executed while"
   i% = i% + 1
WEND
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)