Page 85 - iPro_trackGPT_V5_Class8
P. 85

In  the  preceding  code,  the  while  loop  checks  the
                 condition (i <= 10) that evaluates to true. The statements
                 written inside the body of the while loop get executed.
                 The value of the variable i will be incremented by 1 (i++).
                 The loop checks the condition again and again until the
                 value of the variable  i becomes more than  10. This
                 variable  is also called  a  control  variable.  The  control
                 variable defines the duration until which the loop will
                 execute.

                 The do-while Loop

                 The do-while loop in Java always runs the instructions inside it
                 at least once. After it runs the instructions, it checks a condition.
                 If the condition is true, it runs the instructions again. This keeps
                 happening until the condition is false. Unlike the while loop,
                                                                                                     Start
                 which checks the condition before running the instructions,
                 the do-while loop checks it after running the instructions.
                 The syntax of the while loop is as follows:                               Body of do...while loop

                 do
                 {
                        [statements]
                                                                                        True      Conditional
                        [increment/decrement expression]
                                                                                                  Expression
                 }

                 while(< conditional expression >);
                                                                                                         False
                 For example,
                                                                                                      Stop
                 public class DoWhileLoop

                 {
                     public static void main(String args[])
                     {
                         int i = 1;
                           do

                         {
                              System.out.println("The  value
                                  of i is: " + i);
                             i++;

                         }
                         while (i <= 10);
                     }
                 }






                                                                Conditional, Looping and Jump Statements in Java  83
   80   81   82   83   84   85   86   87   88   89   90