Re: for loop ?
Bernie Ryan wrote:
>ROB
> Why don't you allow us to modify the loop counter in a for loop
> like "C" instead of using "BASIC's" step method ?
Because that kind of thing would cause more problems than it would solve.
When you come across a "for" loop in a Euphoria program, you are absolutely
*guaranteed* that the counter is controlled solely by the "for" loop, and
*cannot* be changed unexpectedly by the programmer. This can help greatly
with debugging, since you *know* the loop counter can't be messed about
with.
If you really *do* need to modify your loop counter for whatever reason,
then instead of this...
for i = 1 to length(s) do
-- whatever
end for
..you can code it like this...
integer i
i = 1
while i <= length(s) do
-- whatever
i += 1
end while
..modifying the loop counter to your heart's content. Not as elegant, I
know, but this way it is obvious that your loop counter is under the
complete control of the programmer. Having these very strong distinctions
between internally-controlled "for" loops and programmer-controlled "while"
loops makes understanding and debugging the code much, much easier.
Be seeing you,
Gabriel Boehme
|
Not Categorized, Please Help
|
|