Why continue is not allowed outside iteration statements
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' 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).
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.
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' 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.
Yes, you're right here. But why not write 'label: while (true) { ... continue label ...; break; }', to make it clear that there is an iteration?
Yes, this would be clearer.
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.
I agree. They are unnecessary though, given that one could write:
label: do { ... break label; ... } while (false);
Michael Day wrote:
Perhaps because 'continue' would implicitly create an iteration, when no iteration construct is apparent in the source code.
That would violate the principle advocated by Dijkstra in 'A Case Against the GO TO Statement' 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.