Shares
facebook sharing button Share
twitter sharing button Tweet
email sharing button Email
linkedin sharing button Share
reddit sharing button Share
tumblr sharing button Share
blogger sharing button Share
print sharing button Print
skype sharing button Share
sms sharing button Share
whatsapp sharing button Share
arrow_left sharing button
arrow_right sharing button
 Krivalar Tutorials 
Krivalar Tutorials

Java continue Statement


<<Previous

Next >>





continue statement

continue statement can be used to start the next iteration in a for, while or do while loop. syntax examples:
	continue;
	continue 
Example 1:

public class Continue {
public static void main(String a[]){
System.out.println("Before for loop");

for(int i=1; i<=5; i++){
	System.out.print("\nloop count "
						+ i + ":");
	for(int j=1; j<=5; j++){
		if(j==i){
			continue;
		}
		System.out.print(" " + j);
	}
}

System.out.println("\n\nAfter for loop");

}
}
The above code would print:
Before for loop

loop count 1: 2 3 4 5
loop count 2: 1 3 4 5
loop count 3: 1 2 4 5
loop count 4: 1 2 3 5
loop count 5: 1 2 3 4

After for loop

continue statement - Example 2






public class ContinueLabel {
public static void main(String a[]){
System.out.println("Before for loop");
outer:
	for(int i=1; i<=5; i++){
			System.out.print("\nloop count "
								+ i + ":");
		for(int j=1; j<=5; j++){
			if(j==i){
				continue outer;
			}
			System.out.print( " " + j);
		}
	}
System.out.println("\n\n After for loop");

}
} 
The above code would print:
Before for loop

loop count 1:
loop count 2: 1
loop count 3: 1 2
loop count 4: 1 2 3
loop count 5: 1 2 3 4

After for loop

<<Previous

Next >>





















Searching using Binary Search Tree