Java Continue Statement

Continue is a keyword in Java. The continue statement skips the current iteration of the statement and continues with the program end. When we don’t want the flow to execute our whole statement and want to break particular iteration then we use continue statement.

Java Continue Statement

import java.util.ArrayList;
import java.util.List;

public class mycontinuestatement {

	public static void main(String args[]) {
		// program to find a number in list
		// Stop the program when number finds

		int search = 10;
		List list = new ArrayList();
		list.add(1);
		list.add(23);
		list.add(5);
		list.add(10);
		list.add(12);
		list.add(27);
		list.add(11);
		list.add(15);

		int size = list.size() - 1;
		while (size > 0) {
			if (list.get(size) == search) {
				System.out.println("number found");
				size--;
				continue;
			}
			System.out.println("number = " + list.get(size));
			size--;
		}
	}

}
Example Output

The syntax of a continue is a single statement inside any loop

jump-statement;    
continue;  

Java Continue Statement

public class mytest{  
public static void main(String[] args) {  
     
    for(int d=1;d<=20;d++){  
        if(d==5){   
        continue; 
        }  
        System.out.println(d);  
    }  
}  
}
Example Output

Share