|
|
![]() |
| Thread Tools | Search this Thread |
#1
| |||
| |||
What is the difference between while statement & do statement? Hi, What is difference between while statement & do statement? |
#2
| |||
| |||
Re: What is the difference between while statement & do statement? 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! |
#3
| |||
| |||
Re: What is the difference between while statement & do statement? A while statement (pre test) checks at the beginning of a loop to see whether the next loop iteration should occur. A do while statement (post test) checks at the end of a loop to see whether the next iteration of a loop should occur. The do statement will always execute the loop body at least once. |
#4
| |||
| |||
Re: What is the difference between while statement & do statement? A "do while....." statement is a looping instruction to a program to repeat a stage in the program while some condition is true - e.g while a variable is negative, or, while one variable is less than another. A "do for ....." statement is a looping instruction to a program to repeat a stage in the program a set number of times - e.g for steps = 1 to 10, or, for steps = 1 to (some variable). |
#5
| |||
| |||
Re: What is the difference between while statement & do statement? Well, there is basically only one difference. In do..while int count = 0; do { cout<<"Hello World"; } while(count = -5); the body is executed first and only then does the compiler come across the while( ) statement and the condition is checked. If true, it goes back to the do line and executes the body of the loop until the condition becomes false. The output of the the above construct would be Hello World In the while statement, the condition is checked first, and only if it returns a true value is the body executed int count = 0; while(count = -5); { cout<<"Hello World"; } There is no output for the above construct. Hope the difference is clear. If you need more assistance, I suggest you read Balaguruswamy's 'Let us C' Source(s): "Let us C" by Balaguruswamy |
![]() |
|
Tags: java, statement, while |
Thread Tools | Search this Thread |
|
![]() | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to use Else and Else If Statement in PHP? | Orton | Software Development | 5 | 05-03-2010 06:49 AM |
How to use If statement in PHP? | Deabelos | Software Development | 4 | 09-02-2010 06:14 AM |
REDIM statement | Amaresh | Software Development | 3 | 28-11-2009 09:27 AM |
What is Echo? What is the difference between Echo and Print statement in PHP? | Preetish | Software Development | 3 | 05-09-2009 01:41 PM |
What is the difference between Msgbox Statement and MsgboxQ function? | SamsherR | Software Development | 2 | 28-02-2009 10:32 PM |