what is the difference between while and do while

A while loop can be used to execute a body of statement when the condition is correct!

The syntax is like :
while(condition){
//statements body
}

Example:
int j=0,i=3;
while(j<i){
System.out.println(j);
j++;
}
Output :
0
1
2

The do...while loop almost same with the while loop except it will execute the statement before the checking the condition !Here you go the syntax :
do{
//statement
}

Example:
/*The j is not smaller that i but it will print the value of j.It won't print any thing if you put this condition on the while loop*/
int j=0,i=0;
do{
System.out.println(j);
}while(j<i);

 Output :
0










Comments

Popular posts from this blog

Reading and Writing Operation of SRAM

Reading & Writing Operation of DRAM

Method to Convert from Stream to Json C#