lua-users home
lua-l archive

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

> It is also used elsewhere in the book. Initially I thought this is a
> cute idiom. But what happens when we mix integers and floats? For
> the purposes of this discussion, let us consider the positive case
> only. Now, the reference manual does not say anything about how
> mixed-number loops are set up.

The manual (3.3.5) says that a for loop is equivalent to the following code:

       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
         local v = var

If you apply the rules for arithmetic and comparison operations
over mixed numbers, explained elsewhere in the manual, you have
the semantics of mixed-number loops. What exactly do you think
is missing?

-- Roberto