lua-users home
lua-l archive

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


Yeah! That's what I want. It is beautiful.

Thank you!

Michael

----- Original Message ----- From: "Bret Victor" <bret@ugcs.caltech.edu>
To: <lua@bazar2.conectiva.com.br>
Sent: Monday, January 08, 2007 3:24 PM
Subject: Re: what's wrong with this loop syntax?


Shmuel Zeigerman <shmuz <at> actcom.co.il> writes:

local function strings(S)
   return function() return S:Next() end
end

for str in strings(S) do
   -- [code]
end

Or better yet:

 for str in S.Next, S do
    -- [code]
 end

This assumes that the function S.Next doesn't change during
the iteration, which is a pretty safe bet.