Page 68 - CTS - CSA TP - Volume 2
P. 68

COMPUTER SOFTWARE APPLICATION - CITS



































           TASK 2: Using continue in a Loop
           public class ContinueExample {
               public static void main(String[] args) {
                   // This program prints even numbers in a loop, skipping odd numbers


                   // Print even numbers in a loop
                   for (int i = 1; i <= 10; i++) {
                       if (i % 2 != 0) {
                           // Skip odd numbers and continue to the next iteration
                           continue;

                       }
                       System.out.println(“Even number: “ + i);
                   }
               }
           }
           Output:

























                                                           53

                               CITS : IT & ITES - Computer Software Application - Exercise 89
   63   64   65   66   67   68   69   70   71   72   73