Core Java Interview Questions and Answers
<< Previous Question Next Question >>
 Question: 2403 Page Views: 

What is the difference between "while" and "do while" statements in Java?



Posted By: Avi Date: 9 November 2009 06:16:44 AM
 Answer:

"while" statement checks the condition at the beginning of a loop to see whether the next loop iteration should occur.

"do while" statement checks the condition at the end of a loop to see whether the next iteration of a loop should occur.

"do while" statement will always execute the loop body at least once.



Posted By: eTechPlanet


Date: 9 November 2009 06:16:44 AM

Do while .. first does some code and then checks for a condition.
do-while is a exit controlled loop.
and
While first validates the condition before processing any code in the loop.
while is an entry controlled loop.
This is the major difference between the two!


Posted By: Johndecruse


Date: 31 January 2010 11:01:31 PM
Post a better Answer if you have
 
(Will show your Gravatar icon)  
  Country flag

Loading
Enter the text as shown in the image hE5c6Z
Related Questions
Core Java : What is the Vector class?

What is the Vector class?

The Vector class provides the capability to implement a growable array of objects
Category: Core Java Date: 11/9/2010 1:28:52 PM
Core Java : What is primordial class loader?

What is primordial class loader?

It is the class that is responsible for loading the class and it is the only in All JVM.
Category: Core Java Date: 11/9/2010 12:56:51 PM
Core Java : What is the difference between a while statement and a do  statement?

What is the difference between a while statement and a do statement?

A while statement checks at the beginning of a loop to see whether the next loop iteration should oc....
Category: Core Java Date: 11/9/2010 11:39:53 AM
Core Java : Is the garbage collection algorithm vendor implemented?

Is the garbage collection algorithm vendor implemented?

yes
Category: Core Java Date: 11/9/2010 11:18:47 AM
Core Java : What is the Map interface?

What is the Map interface?

The Map interface replaces the JDK 1.1 Dictionary class and is used associate keys with values.
Category: Core Java Date: 11/9/2010 11:06:53 AM