lua-users home
lua-l archive

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


Is anyone else interested in adding a python-like "for" statement to lua?
Check out this example:

Python:

  def add_(self, num):
    for item in self.list(): 
      item.add_(num)


Lua:

  add_ = function (self, num)
    local index, item = next(self.list(), nil)
    while index
      item.add_(num)
      index, item = next(self.list(), nil)
    end
  end


Lua with for:

  add_ = function (self, num)
    for item in self.list():
      item.add_(num)
    end
  end