Java Tutorial 23 - Break and Continue in Java - Study Viral
Break – When break statement encountered inside a loop then the loop is terminated and program control resumes with the next statement after the loop structure.
break;
Continue – When continue statement is encountered inside the loop with some condition then continue skipped that particular iteration and loop proceeds with next iteration.
continue;
public class DemoBreakContinue { public static void main(String[] args) { for(int i=1; i<=10 ;i++) { if(i==4) { continue; } System.out.println("i :: "+i); } System.out.println("wow i am out of loop"); } }
public class DemoBreakContinue { public static void main(String[] args) { for(int i=1; i<=10 ;i++) { if(i==4) { break; } System.out.println("i :: "+i); } System.out.println("wow i am out of loop"); } }
0 comments:
Post a Comment