Behavior of continue in do/while loops.
Steven Schveighoffer
schveiguy at yahoo.com
Wed Sep 12 10:24:09 PDT 2007
"Downs" wrote
> Steven Schveighoffer wrote:
>> Nope :) Alienating C/Java developers is not a good idea.
>>
>> -Steve
>>
>>
> miller[] came up with two good alternatives over in #D
> 1) forbidding continue in do/while and replacing it with continue
> do/continue while, or
> 2) adding goto do/goto while statements.
> The first one has the advantage of making it totally impossible for a
> newcomer to trip on this, while the second one has the advantage of not
> breaking existing code.
>
> Whaddya think?
I appreciate that you have issues with the continue statement, but I think
they are very subtle, and very uncommon. That and the fact that precedence
is to have continue re-evaluate the condition will likely result in the
language not changing.
I look at a do-while loop as a while loop that you want to execute at least
once. The whole goal of it was to eliminate having to re-code the loop
contents outside the loop so this would occur. What you want seems to me
like a *restart* of the loop, not a *continuance*. I think making continue
skip the condition is prone to more problems then it is worth (imagine
someone switching a while loop to a do-while and then some kind of infinite
loop occurs because there was a continue statement). I think adding syntax
is not necessary since you can express your version of the loop easily with
the current implementation.
However, seeing as how I never use goto in my code, and there is precedence
for using goto in other constructs (goto case, goto default), I have no
problem with adding goto do (goto while is already handled by continue).
But it's not up to me :)
-Steve
More information about the Digitalmars-d
mailing list