On Mon, Feb 19, 2001 at 05:57:31PM +1100, Bill Bennett wrote:
> Select a response, if it's wrong(1)/wrong(2)/wrong(3), a flag=1
> and the far end of the loop is LOOP UNTIL FLAG=1
> 
> All very well, except that this is a contingency occurring early
> in the process. Even if the flag =1, the process will still
> continue down the loop. I'd like to find a way (other than using
> GOTO) simply to jump out of the loop, jump over the intervening
> subprograms (which are all concerned with continuing after a
> correct response has been received) and simply quitting.

The QBasic statement you want is EXIT DO, or possibly EXIT LOOP (my
memory of such things is a little hazy...)

e.g.

DO
  ...loop stuff...
  If condition Then Exit Do
  ...more loop stuff...
LOOP

Of course, you could still use LOOP UNTIL condition2 if you wanted, as
well as this.  This way you can easily construct multiple exit points
from your loop, which can be handy.  There is also an EXIT FOR, and I
think an EXIT WHILE.

> According to Schneider, it should be possible using only
> sequence, decision and loop. Perhaps even a loop is unnenessary.
> 
> I still can't see how.

And most "modern" languages have exceptions, which provide another
fairly elegant way to achieve the same effect.

Seriously, I know you're in the middle of learning QBasic, but you'd be
much better off (IMHO) learning Python, either from _Learning_Python_
from O'Reilly, or just from the web.  Python is as simple as QBasic in
syntax, but more consistent and *alot* more powerful.  QBasic will teach
you nothing of the wonder of dictionaries/hashes... and for those into
rigorously structured programming, Python is also object-oriented.

Just my thoughts.

-Andrew.

-- 
SLUG - Sydney Linux User Group Mailing List - http://slug.org.au/
More Info: http://slug.org.au/lists/listinfo/slug

Reply via email to