Unconditional loop exists
Timon Gehr
timon.gehr at gmx.ch
Tue Aug 13 08:25:21 PDT 2013
On 08/13/2013 04:56 PM, bearophile wrote:
> Are situations like this, that are potential signs of bugs/mistakes,
> worth reporting with warnings?
>
>
> int foo() {
> // Unconditional 'break' within a loop:
> foreach (immutable _; 0 .. 10) {
> //...
> break;
> }
>
> // Unconditional 'return' within a loop:
> foreach (immutable _; 0 .. 10) {
> //...
> return 0;
> }
>
> assert(0);
> }
>
>
> Bye,
> bearophile
Well, the following is the most generic way to get the first element of
some iterable:
foreach(x;s) return x;
More information about the Digitalmars-d
mailing list