lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

If one must resort to such “trickery” then it would seem that a for loop is probably not the best solution. Perhaps while/do or repeat/until is a better option? We might file this in the same category of self-modifying code.

Of course, it is just a caution, so do so at your own peril and when *you* find a bad case do let us know.

Notice also the same “You should not…” is mentioned for the generic for loop as well.

> In chapter 3.3.5, there is a bit a "strange sounding" warning:
> "You should not change the value of the control variable during the loop."
> ... is this not a bit "over-cautious"?
> e. g. in a typical loop "for i=1,count do ... end", it is quite often
> really useful to repeat a loop sequence by "i=i-1", or to repeat
> complete loop by "i=1" assignment.
> This REALLY can be dangerous? (or can give anybody possibly give some
> illegal / "bad-running" example for such change?)