continue is kind of like goto. Are you familiar with break? It's easier to think about them in contrast:

  • break terminates the loop (jumps to the code below it).

  • continue terminates the rest of the processing of the code within the loop for the current iteration, but continues the loop.

Answer from Dustin on Stack Overflow
🌐
W3Schools
w3schools.com › java › java_break.asp
Java Break and Continue
The break statement can also be used to jump out of a loop. ... The continue statement breaks one iteration (in the loop), if a specified condition occurs, and continues with the next iteration in the loop.
Top answer
1 of 12
531

continue is kind of like goto. Are you familiar with break? It's easier to think about them in contrast:

  • break terminates the loop (jumps to the code below it).

  • continue terminates the rest of the processing of the code within the loop for the current iteration, but continues the loop.

2 of 12
424

A continue statement without a label will re-execute from the condition the innermost while or do loop, and from the update expression of the innermost for loop. It is often used to early-terminate a loop's processing and thereby avoid deeply-nested if statements. In the following example continue will get the next line, without processing the following statement in the loop.

while (getNext(line)) {
  if (line.isEmpty() || line.isComment())
    continue;
  // More code here
}

With a label, continue will re-execute from the loop with the corresponding label, rather than the innermost loop. This can be used to escape deeply-nested loops, or simply for clarity.

Sometimes continue is also used as a placeholder in order to make an empty loop body more clear.

for (count = 0; foo.moreData(); count++)
  continue;

The same statement without a label also exists in C and C++. The equivalent in Perl is next.

This type of control flow is not recommended, but if you so choose you can also use continue to simulate a limited form of goto. In the following example the continue will re-execute the empty for (;;) loop.

aLoopName: for (;;) {
  // ...
  while (someCondition)
  // ...
    if (otherCondition)
      continue aLoopName;
Discussions

tree walker - How do I Interpret a Continue/Break Statement in a Loop? - Programming Language Design and Implementation Stack Exchange
$\begingroup$ @lyxal Yeah the JVM implements loops exactly that way, using gotos, iirc (it's a proper instruction in bytecode, now I'm just waiting for Java itself to support gotos) $\endgroup$ ... For a simple tree-walking interpreter in a language with catchable exceptions, both break and continue statements can be implemented as throwing a specific exception, while ... More on langdev.stackexchange.com
🌐 langdev.stackexchange.com
The Java Loop Continue Control Statement - Explained with Examples - Guide - The freeCodeCamp Forum
Java continue Control Statement The continue statement makes a loop skip all the following lines after the continue and jump ahead to the beginning of the next iteration. In a for loop, control jumps to the update statement, and in a while or do while loop, control jumps to the boolean ... More on forum.freecodecamp.org
🌐 forum.freecodecamp.org
0
September 8, 2019
What’s the difference between break, continue and return?
The break statement results in the termination of the loop, it will come out of the loop and stops further iterations. The continue statement stops the current execution of the iteration and proceeds to the next iteration. The return statement takes you out of the method. More on reddit.com
🌐 r/CodingHelp
5
2
December 4, 2021
Is it bad to use continue?

I use continues pretty often. Whenever they make sense, but not when they don't. I don't see it as bad programming practice, unless it effects readability for that particular context (which just depends on the function in question).

More on reddit.com
🌐 r/java
24
12
January 21, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › java › continue-statement-in-java
Java Continue Statement - GeeksforGeeks
July 23, 2025 - The break statement stops the loop entirely, while the continue statement skips the current iteration and proceeds with the next, allowing the rest of the loop to function as usual.
🌐
Tutorialspoint
tutorialspoint.com › java › java_continue_statement.htm
Java - continue Statement
See the following image to know ... while loop, the continue statement skips the remaining code in the current iteration and immediately checks the loop's condition for the next iteration....
🌐
DataCamp
datacamp.com › doc › java › continue
continue Keyword in Java: Usage & Examples
Java keywordsIntroduction To JavaJava File HandlingJava Language BasicsJava ArraysJava Object-Oriented Programming ... The continue keyword is used to skip the current iteration of a loop (for, while, or do-while) and proceed to the next iteration.
🌐
Programiz
programiz.com › java-programming › continue-statement
Java continue Statement (With Examples)
To learn about the break statement, visit Java break. Here, we will learn about the continue statement. The continue statement skips the current iteration of a loop (for, while, do...while, etc). After the continue statement, the program moves to the end of the loop.
🌐
DigitalOcean
digitalocean.com › community › tutorials › java-continue-statement
Java continue statement | DigitalOcean
August 4, 2022 - Java continue statement is used to skip the current iteration of a loop. Continue statement in java can be used with for, while and do-while loop.
Find elsewhere
🌐
W3Schools
w3schools.com › java › ref_keyword_continue.asp
Java continue Keyword
Java Examples Java Videos Java ... Q&A Java Certificate ... The continue keyword is used to end the current iteration in a for loop (or a while loop), and continues to the next iteration....
🌐
Coderanch
coderanch.com › t › 643518 › java › Java-loop-continue
Java, while loop, try and continue (Beginning Java forum at Coderanch)
December 9, 2014 - For example, in the try statement, after line 17 you could do something like this. while(scan.hasNext()){ scan.next()); } This will clear all input until the end of the line. Eventually hasNext would return false. Then your processing could continue to process the value of the int you got in line 17. If line 17 fails in the exception, then you will end up in the exception handlign routine immediately and the loop i provided above will never be called.
🌐
Career Karma
careerkarma.com › blog › java › how to use the java continue statement
How to Use the Java continue Statement | Career Karma
December 1, 2023 - The Java continue statement stops one iteration in a loop and continues to the next iteration. This statement lets you skip particular iterations without stopping a loop entirely. Continue statements work in for and while loops.
Top answer
1 of 3
12

Throw an exception

For a simple tree-walking interpreter in a language with catchable exceptions, both break and continue statements can be implemented as throwing a specific exception, while the loop sets up a try-catch to detect and handle them.

Consider this pseudocode implementation:

interpret_while(condition, body):
    try {
        while (evaluate(condition) is True):
            try {
                evaluate(body)
            } catch (Continue) {
                // do nothing, just go to next iteration
            }
    } catch (Break) {
       // also do nothing, have already left the loop
    }

interpret_continue():
    raise Continue
interpret_break():
    raise Break

We have two exception types and two try-catches, one inside the loop for continue and one outside for break. If there are nested loops, the innermost one will automatically catch the exception and produce the right semantics. The exception-handling system already innately deals with the necessary stack unwinding, exiting each layer of recursion until you get back to the right place.

This can also allow for labelled breaks: include the label in the exception, and test and re-throw if it doesn't match until it reaches the appropriate surrounding loop.

This is not going to be the most efficient or performant approach, but it's very straightforward to get moving with and leverages the functionality of the host system. A similar approach can be used to implement non-local returns or exception handling within the interpreted language, and those will fit in comfortably with one another.

2 of 3
12

Typically, you need to distinguish between what it means for a statement or expression to "complete normally" or "complete abruptly" (borrowing terminology from the Java Language Specification). An expression which evalutes to a value "completes normally", as does a statement which executes in a normal sequence. On the other hand, a statement or expression which has some effect on the surrounding control-flow "completes abruptly".

A statement or expression could complete abruptly if it:

  • Returns a value from the enclosing function.
  • Throws an exception.
  • Breaks from or continues an enclosing loop.

So generally speaking, these are all handled the same way. A typical solution is to represent the result of a statement or expression as a discriminated union of these possibilities, for example in Rust you might write:

enum EvalResult {
    Normal(Value),
    Return(Value),
    Throw(Value),
    Break,
    Continue,
}

(If you have labelled breaks and continues, or you allow constructs like let foo = loop { break 5; }, then your enum will need to account for those, too.)

Your "eval" function, which evaluates an AST node, returns a result like this. Then when evaluating a loop, you would check for these results and handle them appropriately:

match ast_node {
    // ...
    WhileLoop(cond, body) => {
        loop {
            let cond_result = eval(cond);
            match cond_result {
                Normal(v) => if !v.is_truthy() { break; },
                _ => return cond_result,
            }
            
            let body_result = eval(body);
            match body_result {
                Normal(_) | Continue => continue,
                Break => break,
                Return(_) | Throw(_) => return body_result,
            }
        }
        return Normal(VOID_UNIT);
    },
    // ...
}

Here I'm assuming is_truthy() converts a Value to a native Boolean in the host language, and VOID_UNIT is the value resulting from a statement which doesn't produce a "proper" value.

Note how we return cond_result or return body_result directly when it is necessary to propagate a control-flow effect that this loop isn't supposed to handle itself, for example if the loop body contains a return or throw statement. The same propagation will have to be done elsewhere, e.g. when you add two numbers together, you'll have to propagate control-flow effects from left_result and right_result, in order for those control-flow effects to end up being handled by the eval function for the correct AST node.

🌐
Jenkov
jenkov.com › tutorials › java › while.html
Java while Loops
May 9, 2024 - The continue command is placed inside the body of the while loop. When the continue command is met, the Java Virtual Machine jumps to the next iteration of the loop without executing more of the while loop body.
🌐
Sololearn
sololearn.com › en › Discuss › 2117752 › why-continue-statement-wont-work-in-while-and-do-while-loops
Why continue statement won't work in while and do while loops? | Sololearn: Learn to code for FREE!
Like.. i++; if(i==16) continue; ... Anmol Kumar I guess this is what you are trying to do: public class Program { public static void main(String[] args) { int i=0; while(i<20){ i++; if(i==16) continue; System.out.println(i); } } }
🌐
freeCodeCamp
forum.freecodecamp.org › guide
The Java Loop Continue Control Statement - Explained with Examples - Guide - The freeCodeCamp Forum
September 8, 2019 - Java continue Control Statement ... jumps to the update statement, and in a while or do while loop, control jumps to the boolean expression/condition. for (int j = 0; j...
🌐
BeginnersBook
beginnersbook.com › 2017 › 08 › java-continue-statement
Continue Statement in Java with example
As you may have noticed, the value ... a continue statement, which makes it to jump at the beginning of for loop for next iteration, skipping the statements for current iteration (that’s the reason println didn’t execute when the value of j was 4). Same thing you can see here.
🌐
Scaler
scaler.com › home › topics › java › continue statement in java
Continue Statement in Java | Scaler Topics
April 27, 2024 - The outer continue (executed at i = 2) skips the current iteration of the for loop, thereby skipping the while loop and print statements altogether. Hence, we can conclude that the “continue” statement skips the code of the block in which ...
🌐
Refreshjava
refreshjava.com › java › java-continue-and-return-statement
continue keyword in Java - return keyword in Java - RefreshJava
continue statement can be used only inside for, while and do while loops of java. In case of break statement the control flow exits from the loop, but in case of continue statement, the control flow will not be exited, only the current iteration of loop will be skipped.
🌐
DataCamp
datacamp.com › doc › java › java-break-and-continue
Java Break and Continue
In this example, the break statement is used to exit the loop when i equals 5. As a result, the numbers 0 through 4 are printed. The continue keyword is used to skip the current iteration of a loop and proceed to the next iteration.
🌐
DevQA
devqa.io › java-continue-break-statements
Java's Break and Continue Statements with Code Examples
The continue statement is used to skip the current iteration of a loop and proceed to the next one. This can be valuable when certain conditions warrant skipping the execution of specific loop iterations while continuing with subsequent iterations.