Posts

Showing posts with the label continue

switch statement

The Java switch statement executes one statement from multiple conditions. It is like if-else-if ladder statement. switch statement Syntax switch(expression){ case value1: //code to be executed; break; //optional case value2: //code to be executed; break; //optional ...... default: code to be executed if all cases are not matched; } Program public class switch_example { public static void main(String args[]) { int age = 20; switch(age) { case 10: System.out.println("You are child."); break; case 20: System.out.println("You are teenager."); break; case 30: System.out.println("You are matured."); break; case 40: System.out.println("You are old."); break; default: ...

continue keyword in Java

continue keyword in Java Syntax // condition continue ; Program public class continue_demo { public static void main( String args[]) { for ( int i= 1 ; i<= 10 ; i++) { if (i== 6 ) { continue ; } System.out.println(i); } } } Run Output 1 2 3 4 5 7 8 9 10 Explanation The Java continue statement is used to continue loop. It continues the current flow of the program and skips the remaining code at specified condition. continue keyword in innerloop Program public class continue_inner { public static void main( String args[]) { for ( int i= 1 ; i<= 5 ; i++) { for ( int j= 1 ; j<= 5 ; j++) { if (i== 3 && j== 3 ) { continue ; } ...

break keyword

break keyword in Java Syntax // condition break ; Program public class break_demo { public static void main( String args[]) { for ( int i= 1 ; i<= 10 ; i++) { if (i== 6 ) { break ; } System.out.println(i); } } } Run Output 1 2 3 4 5 Explanation The Java break is used to break loop or switch statement. It breaks the current flow of the program at specified condition. break keyword in inner loop Program public class break_inner { public static void main( String args[]) { for ( int i= 1 ; i<= 5 ; i++) { for ( int j= 1 ; j<= 5 ; j++) { if (i== 3 && j== 3 ) { break ; } System.out.println(i + "-" + j); ...