[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Switch Tables
- From: "W. C. Bubel" <inmatarian@...>
- Date: Thu, 2 Aug 2007 17:10:13 -0400
It's fairly trivial to turn a large if statement, such as
if x == 10 then a()
elseif x == 11 then b()
elseif x == 12 then c() end
into a table like this
switch = { [10]=a, [11]=b, [12]=c };
switch[x]();
However, I'm wondering what the table construction might be for a if series such as this
if x < 10 then a()
elseif x == 11 then b()
elseif x == 12 then c()
else d() end