[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Shorten long boolean IF conditions?
- From: Gregory Bonik <gregory@...>
- Date: Fri, 19 Aug 2011 11:37:49 +0400
Daniel Hertrich wrote:
> I'd like to shorten an if condition such as:
> if strCustomPropertyValue == "inbox" or strCustomPropertyValue ==
> "today" or strCustomPropertyValue == "thisweek" or
> strCustomPropertyValue == "thismonth" or strCustomPropertyValue ==
> "thisyear" or strCustomPropertyValue == "later" or
> strCustomPropertyValue == "someday" or strCustomPropertyValue ==
> "archive" or strCustomPropertyValue == "otherpersons" then
> ...
> end
An alternative to the solution with tables is a vararg function:
function is_one_of(value, ...)
for k, v in ipairs(arg) do
if v == value then return true end
end
end
You can use it like this:
if is_one_of(strCustomPropertyValue,
"inbox", "thisweek", "thismonth", "thisyear", "later",
"someday", "archive", "otherpersons") then
...
end
-- Gregory