[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: RE: Syntactic sugar cravings
- From: Luiz Henrique de Figueiredo <lhf@...>
- Date: Tue, 24 Jul 2001 12:02:59 -0300 (EST)
>> for i=1,getn(l) do
>
>You can write:
>ln = getn(list)
>for i = 1, ln do
> local v = list[i]
>end
No need for this.
In a "for" loop, the limits are computed before the loop starts.
The manual says so:
A for statement like
for var = e1 ,e2, e3 do block end
is equivalent to the code:
do
local var, _limit, _step = tonumber(e1), tonumber(e2), tonumber(e3)
if not (var and _limit and _step) then error() end
while (_step>0 and var<=_limit) or (_step<=0 and var>=_limit) do
block
var = var+_step
end
end
In C it's different. :-)
--lhf