[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: for loops
- From: lhf (Luiz Henrique de Figueiredo)
- Date: Wed, 29 Oct 1997 15:06:10 -0200
We'd like your opinion on whether we should add a FOR loop to Lua:
1. Do you miss FOR loops?
2. What syntax would you suggest?
We have been dicussing the matter and have decided that if we're going to add
FOR loops to Lua then it must be a general kind of FOR (as in C), not just the
numeric type (as in FORTRAN, Pascal or Basic).
In other words, we should be able to traverse a table or a linked list using
Now, the real problem is syntax.
After some heated discussion, we think that the syntax below is ok:
FOR statement1 THEN statement2 WHILE expression DO block END
which is sugar for
WHILE expression DO block; statement2 END
With this FOR you can write:
for i=1 then i=i+1 while i<=10 do s=s+a[i] end
for local i,v=next(t,nil) then i,v=next(t,i) while i do process(i,v) end
for local x=head then x=x.next while x do process(x) end
However, we're not really too happy with this, nor really convinced that Lua
needs a FOR loop.
We'd like your input on this matter.
Luiz Henrique de Figueiredo email: firstname.lastname@example.org
TeCGraf-Grupo de Tecnologia em Computacao Grafica, Dep. Informatica, PUC-Rio
Rua Marques de Sao Vicente 225 voice: +55 21 529-9424
22453-900 Rio de Janeiro, RJ, Brasil fax: +55 21 294-8195