[Color Computer] [Coco] Bug in FOR NEXT ?

William Astle lost at l-w.ca
Thu Jun 1 18:38:56 EDT 2006


Frank Pittel wrote:
> I always that the loop counter was "undefined" outside the loop. By undefined
> I mean that the value is implementation dependant and not guaranteed to be any
> specific value.

Is it me or is there epidemic of words out on internet these days?

It's good practice to treat the value of a loop counter as undefined
outside the loop. Then you can avoid a lot of bugs that occur when, for
example, you change the loop at a later date so it bails out early for
some condition. It may also be that Basic specifies that the loop
counter is undefined outside the loop as well. Certainly with the syntax
used in Basic, there are other means of implementing it than the obvious
"increment the value then test it" method.

Other languages, however, do not specify the loop counter as undefined
outside the loop. In C, for example, assuming the loop runs to
completion rather than bailing out early, the value of the loop counter
is predictable. Of course, C is rather explicit about what is going on
in a for loop and you can do some really funky stuff with for loops in C.


-- 
William Astle
finger lost at l-w.net for further information

Geek Code V3.12: GCS/M/S d- s+:+ !a C++ UL++++$ P++ L+++ !E W++ !N w---
!D !M PS PE V-- Y+ PGP t+@ 5++ X !R tv+@ b+++@ !DI D? G e++ h+ y?



More information about the Coco mailing list