GeekInterview.com
   Home |  Tech FAQ  |   Interview Questions |  Placement Papers |  Tech Articles |  Learn |  Freelance Projects |  Online Testing |  Geeks Talk |  Job Postings |  Knowledge Base | Site Search |  Add/Ask Question

  GeekInterview.com  >  Interview Questions  >  J2EE  >  Java

 Print  |  
Question:  What is the difference between a while statement and a do statement

Answer: A while statement checks at the beginning of a loop to see whether the next loop iterationshould occur. A do statement checks at the end of a loop to see whether the next iterationof a loop should occur. The do statement will always execute the body of a loop at leastonce.


October 10, 2006 05:59:15 #1
 MANISHA PATHAK   Member Since: October 2006    Total Comments: 14 

RE: What is the difference between a while statement a...
 

syntax of while is as :

while(condition)

{

}

In while statement,first condition is checked,if the condition is true then the statements within loop are  executed otherwise statements within loop are not executed.

syntax of do-while as :

do

{

}

while(condition);

In do-while statement,first the statements are executed then condition is checked,if the condition is true then only further the loop is executed otherwise not.

     

 

Back To Question