[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: if statement
- From: Dirk Laurie <dirk.laurie@...>
- Date: Mon, 15 Apr 2013 18:19:03 +0200
2013/4/15 Chris Datfung <chris.datfung@gmail.com>:
> Thanks. In this case, I'm stuck with Lua 5.1, is there anything comparable
> to goto in 5.1?
No. You could make a function of the whole thing and say 'return "Blue"'
instead of 'Decision="Blue"'. But here's a neater solution.
function chosen(x) return tonumber(ChooseSetting(x)) end
Decision = (chosen(a) and chosen(b) and chosen(c) and "Blue")
or (chosen(d) and chosen(e) and "Red")
or (chosen(f) and "Yellow") or "Orange
The logical functions do shortcut evalation, so it will skip unnecessary
tests.