lua-users home
lua-l archive

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



On Mar 25, 2008, at 7:09 PM, RJP Computing wrote:

I like the idea of using foreach, but only if it is going to be in Lua for many versions to
come.

Don't let that stop you! Write your own!

local function ForEach( aTable, aFunction )
    for aKey, aValue in pairs( aTable ) do
        aFunction( aKey, aValue )
    end
end

ForEach( { a = 1, b = 2, c = 3 }, print )

> a	1
> c	3
> b	2

Or something!