TestingDocs.com
    Software Testing website
    • Automation
      • Selenium
      • JBehave Framework
    • Tutorials
      • MySQL Tutorials
      • Testlink
      • Maven
      • Git
    • IDEs
      • IntelliJ IDEA
      • Eclipse
    • Flowcharts
      • Flowgorithm
      • Raptor
    • About

    Java Tutorials

    Java continue Statement

    Overview

    In this tutorial, we will learn about the Java continue statement. When a continue statement is executed the loop iteration is skipped.

    continue statement

    The continue statement is used in iteration loops. When the continue statement is encountered, the remaining part of the loop body in the current iteration is not executed and the control moves to the next iteration. continue is used to skip iterations in a loop if a specific condition is satisfied.

    Example

    Let’s see an example of the continue statement in the while loop. In the while/do while loop, the control moves to the condition part on encountering the continue statement. We will illustrate the use of the continue statement through the following code listing:

    /*
     * continue statement demo
     * Java Tutorials - www.TestingDocs.com
     * 
     */
    public class ContinueDemo {
    
     public static void main(String[] args) {
     int i = 0;
     while (i < 10) {
     i++;
     if (i == 5) { // skip when i is 5
     continue;
     }
     System.out.println("i= "+ i);
     } 
     }
    }

    Java continue statement demo

    Program Output

    i= 1
    i= 2
    i= 3
    i= 4
    i= 6
    i= 7
    i= 8
    i= 9
    i= 10

    Another Example

    Let’s use the continue statement inside a for loop. For example, in the below program, we will skip the for loop when i is an even number. We will illustrate the use of the continue statement through the following code listing.

    public class ContinueDemo {
    
     public static void main(String[] args) {
     // TODO Auto-generated method stub
     for (int i = 1; i < 10; i++) {
     if (i % 2 ==0) {
     continue; // This will skip when i is even
     }
     System.out.println("i=" +i);
     } 
     }
    }

    That’s it. A similar statement the break statement is used to terminate the entire loop.

    —

    Java Tutorials

    Java Tutorial on this website:

    https://www.testingdocs.com/java-tutorial/

    For more information on Java, visit the official website :

    https://www.oracle.com/java/

    Related Posts

    Java Performance

    Java Tutorials /

    Improving Java Performance with Multithreading

    Download Greenfoot Windows

    Java Tutorials /

    Download & Install Greenfoot on Windows

    Java Tutorials /

    Java Static Code Analysis

    Java Tutorials /

    Java Testing Tools

    Java Tutorials /

    Handle Multiple Exceptions in Java

    ‹ Java Abstract Class with Examples› Java break Statement

    Recent Posts

    • ChatGPT Plans Free and PlusChatGPT Subscription Plans
    • Stellar Converter for Database ToolStellar Converter for Database
    • Stellar MySQL Log AnalyzerStellar Log Analyzer for MySQL
    • Stellar Repair for MySQLStellar Repair for MySQL
    • ChatGPT IntroductionChatGPT Capabilities
    • How to secure your SQL Database: Tips and Tricks
    • ChatGPT4 Conversational AI FeaturesChatGPT4 Conversational AI Features
    • Trends in Software EngineeringShaping the Future of Development: Exploring Key Trends in Software Engineering
    • Java PerformanceImproving Java Performance with Multithreading
    • QDrant Vector DatabaseOpen-source Vector Databases
    • Difference between PHP and JavaScript?
    • Bing AI Browser Web ContentBing Conversation Styles
    • ChatGPT PreviewChatGPT Introduction
    • Open Source AI Frameworks TensorFlowOpen Source AI Frameworks
    • Artificial Intelligence Tools

    Back to Top

    Links

    • Contact
    • Privacy Policy
    • Cookie Policy

    www.TestingDocs.com