Page 342 - CITS - Computer Software Application -TT
P. 342

COMPUTER SOFTWARE APPLICATION - CITS




           for(int i = 0; i<= 10; i++) {
           b:
           for(int j = 0; j<=15;j++) {
           c:
           for (int k = 0; k<=20; k++) {

           System.out.println(k);
           if(k==5) {
           break a;
           }

           }
           }
           }
           }
           }
           Output:

           0
           1
           2
           3

           4
           5
           Java continue statement
           Unlike break statement, the continue statement doesn’t break the loop, whereas, it skips the specific part of the
           loop and jumps to the next iteration of the loop immediately.
           Consider the following example to understand the functioning of the continue statement in Java.
           public class ContinueExample {
           public static void main(String[] args) {
           // TODO Auto-generated method stub

           for(int i = 0; i<= 2; i++) {
           for (int j = i; j<=5; j++) {
           if(j == 4) {
           continue;

           }
           System.out.println(j);
           }
           }
           }

           }
           Output:
           0


                                                           329
                               CITS : IT&ITES - Computer Software Application - Lesson 85 - 93
   337   338   339   340   341   342   343   344   345   346   347