lua-users home
lua-l archive

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


--- mlkesl <kaishaku13@hotmail.com> wrote:
> I think many users could be confused by this, as they may also
> have been 'contaminated' by C. :p

It's only (potentially) confusing to a C programmer because of
the syntax.  Really, Lua's for loop is that of BASIC (some
flavors) or PASCAL:

  for i=1 to 100
  end

or

  for i=50 to 1 step -1
  end

As I understand it, the current, C-like syntax was chosen to
avoid introducing new keywords ('to' and 'step').

> I guess the solution is to not use/support for loops.  I
> haven't got too far into lua, but I hope there are not other
> loops/blocks in lua that act this way, creating their own
> little scope to run in...  *wince*

This is precisely what you want.  This is exactly the way any C++
programmer would write the same loop:

  for (int i=1; i <= 100; ++i) {
    ...
  }

'i' is scoped to the loop, and that's the way we want it.

<begin sarcastic jibe>
Of course, if the 'for' really wants to be consistent with the
rest of Lua, the loop index should create a global. ;)
</end sarcastic jibe>

Cheers,
Eric


__________________________________________________
Do You Yahoo!?
Yahoo! Sports - Coverage of the 2002 Olympic Games
http://sports.yahoo.com