Re: OT: The REAL RIddle of DO LOOPS Solved
- From: "Reef Fish" <Large_Nassau_Grouper@xxxxxxxxx>
- Date: 25 May 2006 05:56:24 -0700
Reef Fish wrote:
While I expected my question to alt.lang.basic to take awhile
before getting an answer back for my question (since the
traffic there is less than 1 post per day <G>), I was pleasantly
surprised to have gotten a response from Tom Lake that
turned out to be MOST INFORMATIVE about the programming
language conventions and its existing mess. :-)
This was the paragraph that explained it all:
TL> The problem is that the other language you tried will always
execute a
TL> FOR-NEXT loop at least once (Older MS BASICs such as Applesoft
TL> and TRS-80 Level II BASIC do this) whereas the ANSI standard and
TL> newer MS BASICs will skip the loop altogether if the initial
condition
TL> is not met. It runs fine in QBasic when n>0 and x=0
Here's a follow-up conversation that sheds further light into the
subject:
Stephen Rush wrote:
On Wed, 24 May 2006 20:58:24 -0700, Reef Fish wrote:
After posing my question, someone gave me a qbasic program to
try, and I discovered that "quirk" of skipping the loop altogether.
I didn't realize that's an ANSI standard and see at least two merits
in the OLD standard of executing the FOR - NEXT loop at least
once because,
(a) there may be some CONDITION within the loop for k = 0.
to check the value of X, and for X =0, the program may
wish to branch OUT of the loop to do something else; OR
(b) want to actually execute the LOOP in a negative increment
of -1.
I have not used BASIC or FORTRAN for years. And I am glad
that I don't use any program that abides by the new ANSI
convention. :-)
QuickBasic and friends let you use negative increments in a FOR loop, and
let you use a floating-point loopcounter, so
FOR Q = 2.5 TO -2.5 STEP -0.05
That's good. But if the explicit statement is allowed, the the IMPLIED
step should be obvious ( minus 1 as default) if the second argument
is less than the first. That is,
FOR Q = 0 TO -1
should mean the same as
FOR Q = 0 TO -1 STEP -1
That is indeed the case in the very powerful object oriented language
i use, similar to R, S, or APL. For that language, it allows the FOR
- NEXT construction (though very rarely used or needed) and that's
exactly how it treats an IMPLIED step.
is valid, if Q is a SINGLE or DOUBLE. You can also say
IF [condition]THEN EXIT FOR
anywhere in the loop.
Precisely. That gives the programmer perfect control of what he wants
to do, rather let some ASSUMED standard that is inconsistent with
the logical usage of FOR - NEXT loops, by skipping a loop entirely
without even executing the first step (or initial condition) of a loop.
QuickBasic has more looping options than most
languages. You can actually use DO WHILE, IF [condition] THEN
EXIT DO and LOOP UNTIL in the same loop, although having too many exit
conditions from a loop is a good way to shoot yourself in the foot.
Is QuickBasic different from QBASIC? I was under the impression
that they are the same.
But from your explanation, it appears that they may be different
dialects of BASIC. Is that true?
========== end post from alt.lang.basic
-- Bob.
.
- Follow-Ups:
- Re: OT: The REAL RIddle of DO LOOPS Solved
- From: Lou Thraki
- Re: OT: The REAL RIddle of DO LOOPS Solved
- References:
- OT: The REAL RIddle of DO LOOPS Solved
- From: Reef Fish
- OT: The REAL RIddle of DO LOOPS Solved
- Prev by Date: sum of squared gaussians with non-unit variance, non-centered
- Next by Date: Re: Why I´m right
- Previous by thread: OT: The REAL RIddle of DO LOOPS Solved
- Next by thread: Re: OT: The REAL RIddle of DO LOOPS Solved
- Index(es):
Relevant Pages
|