Friday, February 13, 2015

Do While

Do while is another type of looping and how is it different from while loop. It executes the do part irrespective of the while condition for the first time,you can check the below example.

package Example1;

public class DoWhileExample {

 public static void main(String[] args) {
  // TODO Auto-generated method stub
  int i=10;
  do{
   System.out.println(i);
  }while(i>10);
 }

}


output:
10

In the above example the do block is executed irrespective of whether the while condition is true or false. if the same scenario was used for while loops then nothing is printed in the console reason the while condition is false. >>>Local Variable vs Class Variable
------------------------------------------------------------------------------------------------------------

No comments:

Post a Comment