"For" infinite loop

MattCoder mattcoder at hotmail.com
Sun Aug 12 10:28:35 PDT 2012


On Saturday, 11 August 2012 at 20:38:33 UTC, bearophile wrote:
> bioinfornatics:
>
>> n this case why not using a while loop ?
>
> It uses less lines of code, and with the for loop you have a 
> single place where to put the loop variable initialization, 
> test and increment. This makes the code simpler to read. In 
> this case the test is moved inside the loop, but it's better 
> still than a regular while loop.
>
> Bye,
> bearophile

What about:

foreach(ushort i; 0..256)
   writefln("%d", cast(ubyte)i);

It may look better than for loop. ("Maybe").


More information about the Digitalmars-d-learn mailing list