[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: lua idiom: iteration with skips?
- From: Gregg Reynolds <dev@...>
- Date: Wed, 19 Apr 2006 11:49:45 -0500
Hi,
I need to iterate over a list of items with skip logic. For example, if
item[i] fits some criteria, then skip to item[i+n] else skip to item[i+m].
If I understand the manual, altering an iteration variable is a no-no,
so I can't use a for loop for this.
So here's what I come up with using recursion in psuedo-code:
input = { ... }
output = { ... }
function process(i)
... use input[i] to update output[i]
if ( ... test output[j]... ) then
process(i+m)
else
process(i+n)
end
process(1)
or the like. (I haven't tested this yet.) My question is, what is the
natural, idiomatic way to do this sort of thing in lua? I'm new to it,
so I want to learn the lua way.
-gregg