[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: list iteration for statement
- From: Edgar Toernig <froese@...>
- Date: Fri, 27 Apr 2001 07:34:37 +0200
John Belmonte wrote:
>
> for val in list do
> print(val)
> end
>
> My argument for adding this new form is that it's more terse, less
> error prone (forgetting the local qualifier, etc), and faster if the
> list happens to be a global.
IMHO the most useful feature of it would be that list is only evaluated
once. You may iterate for example over function results without a lot
of hassle:
for key in sorted(table) do ... end
or
for field in split(string, ":") do ... end
or simply:
for x in { "foo1", "foo2", "bar", "baz" } do ... end
Ciao, ET.
PS: Has someone an idea for an alternative syntax? It's so similar
to the regular unordered "for i,v in" loop. I would prefer a syntax
that makes it more obvious that it is an ordered loop and not just
the regular one without the 'v' var.