Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson wrote: On Thursday, 5 February 2015 at 12:31:31 UTC, Stéphane wrote: Syntax for checking if an element exists in a list Hello, I would like to know if there is a better (easier to wite, easier to read, easier to understand) way

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Tobias Pankrath via Digitalmars-d-learn
import std.algorithm; int main(string[] options) { // true if the first option given to this program is either foo, bar, or baz. if(options[1].canFind(foo, bar, baz)) return 0; return 1; }

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Nicholas Wilson via Digitalmars-d-learn
On Thursday, 5 February 2015 at 12:31:31 UTC, Stéphane wrote: Syntax for checking if an element exists in a list Hello, I would like to know if there is a better (easier to wite, easier to read, easier to understand) way to check if an element (string) is in a list of strings. Here are

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Stéphane
On Thursday, 5 February 2015 at 12:35:03 UTC, Tobias Pankrath wrote: import std.algorithm; if(options[1].canFind(foo, bar, baz)) This looks quite OK. Thank you, I did not know about that possibility.

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread anonymous via Digitalmars-d-learn
On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson wrote: Note that D does NOT have default fall through. i.e. switch(myopt) { case opt1, opt2, opt3: do_A(); break; case opt4: do_B(); break; default: do_C(); } is equivalent to

Re: Syntax for checking if an element exists in a list

2015-02-05 Thread Stéphane
On Thursday, 5 February 2015 at 13:31:21 UTC, Nicholas Wilson wrote: Note that D does NOT have default fall through. i.e. Yes, but I thought I read that we always had to explicitely specify one ending statement, as goto, continue... or break; which, in many basic cases, means having to add

Syntax for checking if an element exists in a list

2015-02-05 Thread Stéphane
Syntax for checking if an element exists in a list Hello, I would like to know if there is a better (easier to wite, easier to read, easier to understand) way to check if an element (string) is in a list of strings. Here are the possibilities I see today, as someone who is new to D: 1)