RFC: Behavior of continue in do/while loops.

Downs default_357-line at yahoo.de
Wed Sep 12 11:49:08 PDT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Regan Heath wrote:
> 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.
I know that's not what it _does_, but that wasn't my point.
My point was that it _behaves_ the same, as seen from the *outside*,
leading to misunderstandings.

> 
> 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 know that now.
The problem is that because the two perspectives are so similar,
*despite only one being technically correct*, it's easy to mistake the
other one for the correct one if you learned coding by trial-and-error
(as I did).

> 
> 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".
The point is to prevent such misunderstandings from occuring again by
forcing the programmer to explicitly state what he wants, _independent
of his perspective_. So even if he has the wrong idea of how continue
actually works (as I did), he'll still be able to get the behavior he
expected.

> 
> Regan
 --downs
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.7 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFG6DSkpEPJRr05fBERAuF9AJ4xNOlwp2b6EkLEH1QFHdZ7Fs3oogCeLLog
zzpqAwdpoZujDL6HgoOh+Wo=
=wGHk
-----END PGP SIGNATURE-----



More information about the Digitalmars-d mailing list