Comparing Multiple Values
Derek Parnell
derek at psych.ward
Tue Mar 11 04:23:24 PDT 2008
On Tue, 11 Mar 2008 06:45:14 -0400, okibi wrote:
> I've looked all over the site but can't seem to find if D supports any kind of like IN statement for comparisons. For example, I can do the following in SQL:
>
> select *
> from table
> where value in (1,2,3)
>
> And it will compare it to 1, 2, and 3. Is this possible to do within D's if statement? I hate to go about it as such:
>
> if (value == 1 || value == 2 || value == 3)
> dosomething();
>
> Just seems like this could be written better. Can anyone give me any pointers?
Without thinking too deeply about it, you could use this technique ...
bool[int] goodvalues;
static this()
{
goodvalues = [1:true, 2:true, 3:true];
}
.
.
.
if (value in goodvalues)
dosomething();
--
Derek Parnell
Melbourne, Australia
skype: derek.j.parnell
More information about the Digitalmars-d-learn
mailing list