[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Advanced Programming Structures
Keith Olson writes ...
>
> "SoftNGui" <softngui@earthlink.net> wrote in message
> tk3qgi4kr8a1ac@news.supernews.com">news:tk3qgi4kr8a1ac@news.supernews.com...
> > Keith Olson <s p a m t r a p 0 0 7 @ y a h o o . c o m> wrote
> > in message tk35h8spqrdqaa@corp.supernews.com">news:tk35h8spqrdqaa@corp.supernews.com...
> > > FOR II = 0 TO 1
> > > .
> > > .
> > > .
> > > II=1
> > > IF X=0 THEN II=0
> > > IF Y=0 THEN II=9
> > > IF Y=99 THEN II=10
> > > NEXT II
> > > IF II=10 THEN PRINT "AT BOTTOM"
> > > IF II=11 THEN PRINT "AT TOP"
> > >
> > This code misses the point. It tries to avoid GOTO's because
> > they are bad programming practice. Yet at the same time,
> > changing the for-loop variable II within the loop
> > is also bad programming practice.
> >
> >
>
> I must disagree with you on two points:
>
> 1. Using GOTOs is *not* bad programming practice; using *excessive* GOTOs
> is. The worst I've ever come across is 5 chained GOTOs - in a *commercial*
> program (!)that I was hired to *try* to modify. I try to avoid using GOTOs
> in Applesoft and Atari BASIC because they both use line numbers, and
> remembering where branches go can make renumbering tricky.
>
> 2. Changing programming practice for a specific purpose (i.e. to emulate the
> DO/LOOP structure) and to add to your general programming strategy, instead
> of doing it 'just because', *IS* good programming practice, as long as it is
> clear and consistent. (IMHO)
>
....
Besides, Applesoft BASIC does not have all that many control structures;
so, some fudging on 'good practice' rules is unavoidable.
Changing the loop index within the loop in order to force (or avoid) an
exit at the NEXT test is a fairly common practice. On the other hand, exiting a
FOR-NEXT via an IF-THEN GOTO is common, too. In either case, you have something
of a loop violation.
This way of extending the use of FOR-NEXT is kind of neat, at least as an
option to consider. You will lose a bit of speed and compactness; but, you may
gain improved modularity and easier to follow code.
Rubywand