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
Typically, you need to distinguish ... 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... More on langdev.stackexchange.com
🌐 langdev.stackexchange.com
Advice on defending the use of continue and break in a foreach loop in Java
He is wrong. Multiple return points are a good thing. Returning once done makes the code more concise. Show him Martin Fowler's discussion of break, continue and multiple returns in the refactoring "Remove Control Flag" in his book Refactoring Improving The Design Of Existing Code. More on reddit.com
🌐 r/java
20
7
July 19, 2011
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
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
🌐
Tutorialspoint
tutorialspoint.com › java › java_continue_statement.htm
Java - continue Statement
C++ ... The continue statement can be used in any loop control structure to skip the current iteration and jump to the next one. In a for loop, it immediately transfers control to the update statement, while in a while or do-while loop, it jumps ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › continue-statement-in-java
Java Continue Statement - GeeksforGeeks
July 23, 2025 - In the case of a for loop, the continue keyword forces control to jump immediately to the update statement. Whereas in the case of a while loop or do-while loop, control immediately jumps to the Boolean expression.
🌐
Programiz
programiz.com › java-programming › continue-statement
Java continue Statement (With Examples)
In the above example, we have used the for loop to print the sum of 5 positive numbers. Notice the line, ... Here, when the user enters a negative number, the continue statement is executed. This skips the current iteration of the loop and takes the program control to the update expression of the loop. Note: To take input from the user, we have used the Scanner object. To learn more, visit Java Scanner.
🌐
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.
🌐
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
🌐
Oracle
docs.oracle.com › javase › tutorial › java › nutsandbolts › branch.html
Branching Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)
The continue statement skips the current iteration of a for, while , or do-while loop. The unlabeled form skips to the end of the innermost loop's body and evaluates the boolean expression that controls the loop. The following program, ContinueDemo , steps through a String, counting the occurrences ...
🌐
Baeldung
baeldung.com › home › java › core java › the java continue and break keywords
The Java continue and break Keywords | Baeldung
January 8, 2024 - But when counter equals 3, the if condition becomes true and the break statement terminates the loop. This causes the control flow to be transferred to the statement that follows after the end of for loop. In case of nested loops, an unlabeled break statement only terminates the inner loop that it’s in. Outer loops continue execution:
🌐
CodeSignal
codesignal.com › learn › courses › iterations-and-loops-in-java › lessons › navigating-loop-control-mastering-break-and-continue-in-java
Navigating Loop Control: Mastering Break and Continue in ...
The keyword continue in Java is analogous to skipping a boring view during a walk. It disregards the current loop iteration and jumps ahead to the next one. ... Be a part of our community of 1M+ users who develop and demonstrate their skills on CodeSignalStart learning today! Our output presents admiration logs for ...
🌐
GeeksforGeeks
geeksforgeeks.org › java › break-and-continue-statement-in-java
Break and Continue statement in Java - GeeksforGeeks
class GFG { public static void ... conditions. The continue statement in Java is used to skip the current iteration of a loop and move directly to the next iteration....
Published   March 6, 2026
🌐
DataCamp
datacamp.com › doc › java › java-break-and-continue
Java Break and Continue
It does not terminate the loop; instead, it causes the loop to jump to the next iteration. ... public class ContinueExample { public static void main(String[] args) { for (int i = 0; i < 10; i++) { if (i % 2 == 0) { continue; // Skip even numbers } System.out.println(i); } } }
🌐
Medium
medium.com › @iamthatsoftwareguy › understanding-break-continue-and-labeled-statements-in-java-loops-8bdfa932c28a
Understanding break, continue, and Labeled Statements in Java Loops | by iamthatsoftwareguy | Medium
October 15, 2024 - In a for loop, it goes to the next update (like i++). In a while or do-while, it checks the condition again. continue;: Skips to the next round of the nearest loop.
🌐
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 ...
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.

🌐
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.
🌐
iO Flood
ioflood.com › blog › java-continue
Java's Continue Keyword: A Usage Guide with Examples
February 20, 2024 - If it is, the ‘continue’ statement is executed. This immediately stops the current iteration and jumps to the next one, skipping the print statement for even numbers. As a result, only odd numbers between 0 and 10 are printed.
🌐
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 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 ...
🌐
DevQA
devqa.io › java-continue-break-statements
Java's Break and Continue Statements with Code Examples
Search and Exit: When searching for an element in an array, you can use the break statement to terminate the loop as soon as the element is found. Data Validation: While processing user input, you might use the continue statement to skip processing invalid data and prompt the user to reenter valid data. Performance Optimization: In certain cases, you can use the continue statement to avoid unnecessary computations for specific inputs. The break and continue statements in Java are powerful tools that allow programmers to control the flow of execution within loops.