Wednesday, 4 November 2020

The do......while Loop in JAVA

 

 

The do......while Loop  :-



A   do.....while  loop is similar  to a while loop , except that a do .....while loop  is guaranteed to  execute  at least one time.


The syntax of a do.....while loop  is :-


do 

   {

           //Statements

    }

while(Boolean_expression);



Notice  that  the Boolean  expression  appears at  the end of loop , so the  statement  in the loop  execute once  before  the  Boolean  is tested.  If  the Boolean  expression  is true, The  flow  of  control  jumps  back  up to do ,  and  the  statement  in  the loop  execute again.This  process repeats  until the Boolean expression is false.


 EXAMPLE :-

 

 public class Test 

 {

    public static void main(String  args[])

     {

          int x =10;

          do

             {

                  System.out.print("value of x :" +x);

                   x++;

                   System.out.print("\n");

                }

                    while(x <15);

 

       }

 

  }



OUTPUT :-

value of x : 10

value of x : 11

value of x : 12

value of x : 13

value of x : 14




No comments:

Post a Comment

Student Marks Calculation app using java

      import javax.swing. *; import java.awt.event.ActionEvent ; import java.awt.event.ActionListener ; public class Student { private J...