lua-users home
lua-l archive

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


>t={1,2,3,'eww'}
>for elt in t do
>	do_whatever(elf)
>end
>
>This is not the most general 'for' you can think of, but this is what I do
>most of the time: go through a table and look at each element. Sure, you
>can do it using next etc, but this would be much less hassle.
>

This will be catered for in 3.1 with a new builtin function 'foreach'.
With this, your example will be written
	foreach(t,do_whatever)
or something like that.
Moreover, 3.1 will bring dynamic function closures so you'll be able to write

	foreach(t,function (x) print(x.name) end)

--lhf