Proposal of a general do-while loop

Rioshin an'Harthen rharth75 at hotmail.com
Sun Jul 22 05:27:34 PDT 2007


"Charles D Hixson" <charleshixsn at earthlink.net> kirjoitti viestissä 
news:f7t5ki$1mn0$1 at digitalmars.com...
> I'd prefer the Ada-esque
>      exit when (pos == string::npos);
> but that means introducing new key words (more than just "loop").  OTOH, I 
> guess there's nothing wrong with having an un-parameterized "do" instead 
> of loop, as in:
>    do
>    {  ... do stuff ...
>       when(condition) break;
>    }
> in the case the "when" is semantically the same as an if, but it clarifies 
> what's going on.  One could limit it's use to "only usable within a do 
> loop".  But I would prefer the syntax of either:
>       exit when (condition);
> or
>       break when (condition);
> as I feel that these are clearer.

I'd say no to a new keyword just for this.

However, a syntax like

    break if (condition);

would, in my opinion, be better than

    if (condition) break; 




More information about the Digitalmars-d mailing list