LLVM Coding Standards
spir
denis.spir at gmail.com
Tue Apr 12 03:24:38 PDT 2011
On 04/12/2011 03:15 AM, Daniel Gibson wrote:
>> While I am on the subject, I've *always* thought major languages have
>> > poor loop constructs:
>> >
>> >
>> > (A)
>> >
>> > for (;;)
>> > {
>> > std::getline(is, line);
>> > if (line.size() == 0)
>> > break;
>> > ...some things...
>> > }
>> >
> (...)
>> >
>> > Instead you could just have:
>> >
>> > loop
>> > {
>> > ...
>> > if (condition) exit;
>> > ...
>> > }
>> >
>> > instead of WHILE and DO. Whereby you *must* have an exit condition.
>> >
>> >
>> > But I suppose you need a FOR loop because the following may be error prone.
>> >
>> > int x=0;
>> > loop
>> > {
>> > if x> 9 exit;
>> > ...
>> > x++;
>> > }
> Yeah. And I guess while-loops also have their uses.
> I think just loop like you're suggesting is not available because
> for(;;) and while(1) achieve the same thing without too much additional
> typing.
I've been thinking of a loop construct allowing either while or until, each
either at start or end, or even both:
loop [(while|until) condition] {
body
} [(while|until) condition]
Side-Note: I favor until over while because I "feel" (for what reason?)
booleans should be initially false, or false by default, thus the end-condition
should express a change and be positive.
loop until end1 {
body
} until end2
ends are initially false
loop while end1 {
body
} while end2
ends are initially true
Denis
--
_________________
vita es estrany
spir.wikidot.com
More information about the Digitalmars-d
mailing list