RFC: Behavior of continue in do/while loops.

Regan Heath regan at netmail.co.nz
Wed Sep 12 11:19:41 PDT 2007


Downs wrote:
>> However,  if you think of 'continue' as meaning 'go to the next
>> iteration' then you would expect it to do whatever it would have done at
>> the end of this iteration, before the next one.
> 
>> If you think of 'continue' as meaning 'go back to the start of
>> the(this?) loop' then you wouldn't expect the condition to be evaluated.
> 
> The problem here is that for every case *but* a do/while loop, the two
> perspectives behave exactly the same. See my follow-up to the other post
> for a way to prevent this conflict.

I don't agree, 'go back to the start of this loop' simply isn't what 
'continue' does, in _any_ case.  In all cases when you execute continue 
you move from iteration n to n+1.  Moving from one iteration to the next 
_always_ involves checking the loop condition.

The only difference between do/while and the other loops is that the 1st 
iteration is 'unprotected' by the guarantee of the loop condition. 
That's it.

Expecting continue to 'go back to the start of this loop' is simply 
incorrect thinking.  If you really want to 'go back to the start of this 
loop' you have to use goto.

I don't really see the point in either of the solutions you have in the 
other thread, but then "it's not up to me".

Regan



More information about the Digitalmars-d mailing list