The 'continue' keyword in Java (and probably in many other programming languages) is used to skip further execution of the current iteration.
Why was the name 'continue' chosen? Why not something more straightforward like 'skip' ?
Software Engineering Stack Exchange is a question and answer site for professionals, academics, and students working within the systems development life cycle. It only takes a minute to sign up.
Sign up to join this communityWhile most likely not a very big difference and programmers would have been able to handle it just the same:
"continue" makes it clear that the loop will go on processing data (stop the details, continue the loop), while "skip" could be thought of as terminating the loop totally (like break in C++). It's one of those cases where it can be difficult to find the "perfect" name for some functionality. Ruby and Perl use "next" in similar situations which to me seems a slightly better choice.
next
is that in some languages (e.g. Basic) next
is the end of a for
loop, so it might be confusing for some programmers with a background in those languages.
Dec 18, 2012 at 11:07
next
to mark the end of a for
loop?
Dec 18, 2012 at 11:57
I guess it might have to do with history of programming languages.
To ask why it is continue in Java is to ask why it is continue in C++, which is to ask why it is continue in C, Algol etc.
To my knowledge, Fortran was the first to have a CONTINUE statement, actually a no op. It was just there to make it possible to place a (numeric) label used in goto or other constructs like:
DO 42 i=1,100
A[i] = 0
42 CONTINUE
The first line introduces a do loop that, when completed, continued execution at label 42.
DO
statement is the reference to the last statement of the loop (I believe that guys who designed INTERCAL, a parody programming language, drew their inspiration for COMEFROM statement from this feature of FORTRAN). In a loop like this you might put the label on assignment statement, but having a separate CONTINUE
is handy if eventually you want to insert something at the end of loop body (especially if your program is on a batch of punched cards).
I always thought of it as just continuing processing data and therefore it was named "continue". I have never seen anyone have issues with the choice of the continue keyword not being straightforward enough.
C
? Why do you think "skip" is more straight forward than "continue"? Why not "jump over"? Why not "do again"?