Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Python Programs
    • Java Programs

Java Continue Statement

by suresh

The Java Continue statement is one of the most useful statements that control the flow of loops. We generally use this statement inside the For Loop, While Loop and Do While Loop. While executing these loops, if the Javac compiler finds the Java Continue statement inside them, it will stop the current loop iteration and starts the new iteration from the beginning.

For example, If we have ten statements inside a loop. If we want to skip executing the second 5 statements (statement 6 — statement 10) when a certain condition is True; otherwise, it has to execute all the ten statements inside the loop. In this situation, we place the If Statement after the 5th statement and within the if block place the Java continue statement. If the condition is True, the Javac compiler will stop executing statements 6 to 10. Otherwise, it will execute statements 1 to 10.

Java Continue examples

The syntax of the Continue Statement in Java Programming language is as follows:

continue;

We want to share two examples to display the working functionality of the Java Continue in both For loop and While loop

Java Continue in For Loop

In this Java program, we will show how to use Continue Statement in Java For Loop with example.

This program allows the user to enter any integer value. Then it will display the Even and Odd numbers inside the given range.

// Java Continue Statement
package ConditionalStatements;

import java.util.Scanner;

public class ContinueStatement {
	private static Scanner sc;
	public static void main(String[] args) {
		int number;
		sc = new Scanner(System.in);		
		System.out.println(" Please Enter any Integer Value: ");
		number = sc.nextInt();
		int i;
		for (i = 1; i <= number; i++)  {
			if(i % 2 != 0)  {
				System.out.format("\n Odd Numbers = %d (Skipped By Continue)\n", i);
				continue;
			}
			System.out.format(" Even Numbers = %d ",i);
		}
	}
}

OUTPUT

Java Continue Statement 1

ANALYSIS

  • In this Java continue statement example, we are not going to explain the for loop. If you do not understand Java for loop, then please visit our article For Loop.
  • Inside the for loop we placed If Statement to test whether (i % 2 != 0).
    • If this condition is True, then the continue statement executed, and the iteration will stop at that number without printing the other statement: System.out.format(” Even Numbers = %d “,i);.
    • If the condition is false, then it will skip the Java continue statement and prints that value as output (In Our case Even Number).

Java Continue Statement in While Loop Example

In this Java program, we will show how to use Java Continue Statement inside the While Loop with example.

This program allows the user to enter any integer values. Next, it uses the continue statement, and it will display all the values from 0 to a given number except 4 and 8.

/ Java Continue Statement in While Loop example

package ConditionalStatements;

import java.util.Scanner;

public class ContinueinWhile {
 private static Scanner sc;
 public static void main(String[] args) {
 int number;
 sc = new Scanner(System.in); 
 System.out.println(" Please Enter any Integer Value below 10: ");
 number = sc.nextInt();
 int i = 0;
 while (i <= number)  {
 if(i == 4 || i == 8)  {
 System.out.format(" Skipped By Continue = %d \n", i);
 i++;
 continue;
 }
 System.out.format(" Values = %d \n", i);
 i++;
 }
 }
}

OUTPUT

Java Continue Statement 2

ANALYSIS

Here we are not going to explain the While loop. If you do not understand While loop, then please visit our article Java While Loop. Inside the While loop, we placed If Statement to test whether i is equal to 4 or 8.

  • If this condition is True, the Java continue statement will be executed, and the iteration will stop at that number without printing the other statement: System.out.format(” Values = %d \n”, i);. For better understanding, we placed System.out.format(” Skipped By Continue = %d \n”, i); inside the If condition. So, whenever the iteration break, that value be printed from this statement.
  • If the condition is false, then it will skip the continue statement and prints that number as output (In Our case 0,1,2,3,4,6,7,8,10).

Placed Under: Java

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial
  • C Tutorial
  • C# Tutorial
  • Java Tutorial
  • JavaScript Tutorial
  • Python Tutorial
  • MySQL Tutorial
  • SQL Server Tutorial
  • R Tutorial
  • Power BI Tutorial
  • Tableau Tutorial
  • SSIS Tutorial
  • SSRS Tutorial
  • Informatica Tutorial
  • Talend Tutorial
  • C Programs
  • C++ Programs
  • Java Programs
  • Python Programs
  • MDX Tutorial
  • SSAS Tutorial
  • QlikView Tutorial

Copyright © 2021 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy