lua-users home
lua-l archive

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


On Thu, Jun 30, 2011 at 13:39, Philippe Lhoste <PhiLho@gmx.net> wrote:
> On 29/06/2011 18:15, Dirk Feytons wrote:
>>
>> for k,v in pairs(t) do
>>   t[k] = nil
>>   if (<some condition>) then
>>     t[k] =<some other value>
>>   end
>> end
>
> Unless I am missing something (maybe the real code is much more complex),
> you can rewrite it as:
>
> for k, v in pairs(t) do
>  if (<some condition>) then
>    t[k] = <some other value>
>  else
>    t[k] = nil
>  end
> end
>
> no?

The real code is more complex :)
For the sake of readability it was better to return a new table
instead of modifying the existing one.

-- 
Dirk