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' ?

closed as not constructive by Oded, Charles Salvia, Robert Harvey, GrandmasterB, Dynamic Dec 20 '12 at 21:14

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. If this question can be reworded to fit the rules in the help center, please edit the question.

  • 10
    Apart from the legacy of C? Why do you think "skip" is more straight forward than "continue"? Why not "jump over"? Why not "do again"? – Oded Dec 18 '12 at 11:07
  • @Oded Yup, it could be anything. 'skip' was just an example. – Krishnaraj Dec 18 '12 at 13:11

While 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.

  • 2
    The problem with 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. – user281377 Dec 18 '12 at 11:07
  • 24
    stopCurrentActionAndContinueProcessingFromTheNextItemInThisLoop; – Juha Untinen Dec 18 '12 at 11:40
  • @user281377: Do any languages other than BASIC use next to mark the end of a for loop? – Keith Thompson Dec 18 '12 at 11:57
  • @JuhaUntinen perfect! And thanks to modern IDEs long names are a problem of the past ;-) – Simon Bergot Dec 18 '12 at 12:55
  • 1
    @Keith: We are all spoiled :) – thorsten müller Dec 18 '12 at 19:39

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

The first line introduces a do loop that, when completed, continued execution at label 42.

  • It's ironic that other languages would borrow the statement from a language where it was a no-op. I wonder how the loops were implemented on the old machines? One DSP I used had an assembly-language instruction that worked like FORTRAN do-loop: one specified the address preceding the instruction following the loop, and it would set a special flag and load a special register with that address following that, and load another special register with the one following the "loop-start" instruction.. Whenever the code-fetch unit read a word from the first special register... – supercat Mar 27 '14 at 21:23
  • ...and the loop flag it was set, it would load the program counter with the value in the second, decrement a counter, and if it reached zero, clear the loop flag. Like FORTRAN, the DSP forbade branching instructions immediately before the end of the loop (to avoid a pipeline stall, the program counter would get loaded with the loop start address before the last couple instructions were executed, so jumps there would cause confusion). – supercat Mar 27 '14 at 21:27
  • Not exactly so. In FORTRAN, the label in 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). – ach Mar 4 '15 at 18:44

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.

  • When you ask someone to continue they usually keep doing what they were doing but here the iteration is skipped. I think 'next' would have been a better suitable keyword as mentioned in the answer. – Krishnaraj Dec 20 '12 at 18:00

Not the answer you're looking for? Browse other questions tagged or ask your own question.