lua-users home
lua-l archive

Definion of 'for' statement in the manual

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


The reference for Lua 5.2 says:
 """
 More precisely, a 'for' statement like
 for v = 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
 local v = var
 block
 var = var + step
 end
 end
 """
Whereas the reference for Lua 5.3 says it's equivalent to:
 """
 do
 local var, limit, step = tonumber(e1), tonumber(e2), tonumber(e3)
 if not (var and limit and step) then error() end
 var = var - step
 while true do
 var = var + step
 if (step >= 0 and var > limit) or (step < 0 and var < limit) then
 break
 end
 local v = var
 block
 end
 end
 """
My question:
Why does Lua 5.3's reference does "var = var - step" instead of simply
moving the "var = var + step" after "block" (as in Lua 5.2)?

AltStyle によって変換されたページ (->オリジナル) /