Why continue is not allowed outside iteration statements

David-Sarah Hopwood david.hopwood at industrial-designers.co.uk
Tue Nov 25 21:32:36 PST 2008


Michael Day wrote:
> 
>> Perhaps because 'continue' would implicitly create an iteration, when no
>> iteration construct is apparent in the source code.
> 
> A reasonable response :)
> 
>> That would violate the principle advocated by Dijkstra in
>> 'A Case Against the GO TO Statement'
>> <http://www.cs.utexas.edu/~EWD/transcriptions/EWD02xx/EWD215.html>, since
>> the start of every block (not even just every labelled block) would be a
>> possible jump target, with no explicit indication that you need to keep
>> track of the number of iterations of the block in order to describe the
>> progress of that function execution.
> 
> The start of every block? Why not just the start of labelled blocks?
> (Assuming that continue outside of an iteration statement would require
> a target label, just as break currently requires a target label when
> used outside of an iteration statement).

Yes, you're right here. But why not write
'label: while (true) { ... continue label ...; break; }', to make it
clear that there is an iteration?

> Currently the end of every labelled block is a possible jump target, and
> it seems that the language could be simplified if break was not allowed
> outside of iteration statements. But code might already depend on this.

Forward jumps are less problematic than backward jumps -- in terms of
Dijkstra's argument, they do not require an index to keep track of the
number of iterations.

-- 
David-Sarah Hopwood


More information about the Es-discuss mailing list