boolean over multiple variables

Pelle Månsson pelle.mansson at gmail.com
Tue Jan 26 04:28:15 PST 2010


On 01/26/2010 01:02 AM, Nick Sabalausky wrote:
> "strtr"<strtr at spam.com>  wrote in message
> news:hjd6t1$beh$1 at digitalmars.com...
>> This may be is a very basic question, but is there a way to let me omit a
>> repeating variable when doing multiple boolean operations?
>>
>> if ( var == a || var == b || var == c || var == d)
>> if ( var == (a || b || c || d) )
>
> I do this:
>
> -------------------------
> import tango.core.Array;
>
> void main()
> {
>      if( [3, 5, 6, 12].contains(7) )
>      {
>      }
> }
> -------------------------
>
> There's probably a phobos equivilent, too.
>
> Alhough, I would much prefer what other people mentioned about having "in"
> refer to the values of a collection rather than the keys. But I've been
> using the above as a substitute.
>
>
I think in should work for keys in an associative array and for values 
in a regular array.

This is how it works in python.


More information about the Digitalmars-d-learn mailing list