'in' for arrays?
Alexander Panek
a.panek at brainsware.org
Wed Dec 6 03:21:31 PST 2006
Lionello Lunesu wrote:
> Egor Starostin wrote:
>>> I keep wanting to say
>>> if (val in somearray) {
>>> }
>> Me too.
>>
>> For example, in Python I can write
>>
>> if val in ('off','disable','no')
>
> OK, granted, if (val in ["off","disable","no"]) does look cool, but a
> switch(val) would still be faster (uses binary search if I'm not mistaken).
>
> Maybe D should get an alternative "if" for this construct:
>
> switch(val) {
> case "off","disable","no":
> // code here
> default:
> break;
> }
May I ask in what way this is different from:
switch ( val ) {
case "off":
case "disable":
case "no":
// code here
break;
}
?
>
> Anyway, supporting "in" for normal arrays has my vote. In my post I just
> mentioned a possible concern.
>
> L.
Kind regards,
Alex
More information about the Digitalmars-d
mailing list