Page 162 - CA_Blue( J )_Class10
P. 162

8          } while(a >= 1);
                 9      }

                10  }
              •  Finite Loop: When a loop executes a finite number of times, then the loop is known as a finite loop. The two types
                 of finite loops are:
                ▪  Continuous Loop: Here the increment or decrement changes by 1 only for each iteration.
                    Example: Print all the natural numbers up to 10.
                   for (i=1; i<=10; i++)
                   {
                       System.out.println(i);
                   }
                ▪  Step Loop: In the step loop, the loop control variable increases or decreases by more than one.
                    Example: Prints the even numbers up to 20.

                   for (i=2; i<=20; i=i+2)
                   {
                       System.out.println(i);
                   }
                             To increase a variable by 1 and decrease a variable by 2 unless the variable becomes greater than
                Program 1
                             the second variable.
                 1  class more_expression_for

                 2  {
                 3      public static void main()

                 4      {
                 5          int i,j;

                 6          for(i=1,j=20; i<=j; i++,j=j-2)
                 7          {
                 8              System.out.println(i+ " : "+j);

                 9          }

                10      }
                11  }

              You will get the following output:






















                160160  Touchpad Computer Applications-X
   157   158   159   160   161   162   163   164   165   166   167