answersLogoWhite

0


Best Answer

do

{

//statements

}while(condition);

The statements inside the block get executed at-least once, no matter what condition you have placed. Only from the 2nd time the condition is checked, simply because the condition is at the last.

for(initialization; condition; updation)

{

//statements

}

Here the statements don't get executed even once if the condition fails initially. The condition is at the entry itself.

User Avatar

Wiki User

13y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

14y ago

A do while loop will evaluate a certain condition at the end of every loop. It is up to the programmer to increment variables. A for loop includes the variable incrementing, and checking the end of the loop, as part of its basic syntax, so, if a variable must be increment, the syntax of a for loop is usually shorter. It is normally used when you know in advance how often you have to repeat certain commands. However, in theory you can get along without a for loop; it is just a shorter way of writing certain kinds of loops.

A do while loop will evaluate a certain condition at the end of every loop. It is up to the programmer to increment variables. A for loop includes the variable incrementing, and checking the end of the loop, as part of its basic syntax, so, if a variable must be increment, the syntax of a for loop is usually shorter. It is normally used when you know in advance how often you have to repeat certain commands. However, in theory you can get along without a for loop; it is just a shorter way of writing certain kinds of loops.

A do while loop will evaluate a certain condition at the end of every loop. It is up to the programmer to increment variables. A for loop includes the variable incrementing, and checking the end of the loop, as part of its basic syntax, so, if a variable must be increment, the syntax of a for loop is usually shorter. It is normally used when you know in advance how often you have to repeat certain commands. However, in theory you can get along without a for loop; it is just a shorter way of writing certain kinds of loops.

A do while loop will evaluate a certain condition at the end of every loop. It is up to the programmer to increment variables. A for loop includes the variable incrementing, and checking the end of the loop, as part of its basic syntax, so, if a variable must be increment, the syntax of a for loop is usually shorter. It is normally used when you know in advance how often you have to repeat certain commands. However, in theory you can get along without a for loop; it is just a shorter way of writing certain kinds of loops.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

A do while loop will evaluate a certain condition at the end of every loop. It is up to the programmer to increment variables. A for loop includes the variable incrementing, and checking the end of the loop, as part of its basic syntax, so, if a variable must be increment, the syntax of a for loop is usually shorter. It is normally used when you know in advance how often you have to repeat certain commands. However, in theory you can get along without a for loop; it is just a shorter way of writing certain kinds of loops.

This answer is:
User Avatar

User Avatar

Wiki User

14y ago

Compare them:

for (exp1; exp2; exp3) stmt
while (exp) stmt
do stmt while (exp);

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between do while and for loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What the difference between pretest loop and posttest loops?

The difference is that pre means before and post means after in Latin so it's tested before or after. :)


Compare Do-While with While Statements?

A Do-While loop looks like this: do { loop body } while (condition); and a While loop looks like this: while (condition) { loop body } The main difference is that the loop body is always run once in the Do-While loop, then the condition is checked to see if the loop should keep running. In a While loop, the condition is checked first, and it will not run the loop body at all if the condition is false.


What is the difference between a loop and a whorl fingerprint?

That a loop is curved and a whorl is shaped like a wave.


What are the types of loops?

There are three forms of loop commonly used in C/C++, the for loop, the while loop and the do-while loop. The for loop is most commonly used whenever an action is going to be performed a set amount of times. For example, to sum every element in an array: for(i = 0; i < arraySize; i++) { sum = sum + array[i]; } The while loop and do-while loop are commonly used to loop until a condition is met. The difference between the two is that the do-while loop goes through one iteration before checking its condition, while the while loop checks its condition before any execution of the loop. Example do-while loop: do { randomNumber = rand() % 10; }while(randomNumber != 6); Example while loop: cout > number; while(number < 0) { cout > number; }


What is difference between for loop and do-while loop?

The do loop is similar to the forloop, except that the expression is not evaluated until after the do loop's code is executed. Therefore the code in a do loop is guaranteed to execute at least once. The following shows a do loop in action: do { System.out.println("Inside do while loop"); } while(false); The System.out.println() statement will print once, even though the expression evaluates to false. Remember, the do loop will always run the code in the loop body at least once. Be sure to note the use of the semicolon at the end of the while expression.

Related questions

What is the difference between a do while loop and a for loop in c?

the counter variable cannot be initialized in while loop before entering into the block.


What is the Difference between while and do while?

Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.


What is the difference between if and while loop?

Easy: if-else is not a loop; while, for and do-while are loops.if-else just run once, but do-while run many times.


Difference between for and while loop not in syntactically?

Well 'while' goes like this: while (condition) statement 'for': for (initialize; condition; after-each-loop) statement


Is a while loop or a for loop faster?

No difference.


What is the difference between while loop and for loop in oracle?

You mean PL/SQL? Well, they are different things, read the manual for details.


What is the difference between do and while loops in c?

the main difference b/w do and while loops is that do loop will run atleast once even if condition is not satisfied but while loop will not execute even once if condition is not satisfied . this is bcoz in do loop condition is checked after one execution but in while condition is prechecked.


Difference between while and do while loops in java?

The most important differences are: a. The while loop starts with a condition whereas the condition is the line of code in case of a do while loop b. The do while loop is guaranteed to run the loop body atleast once even if the condition is an impossible to satisfy but such a guarantee is not available with the normal while loop


Open loop and close loop system in injection moluld machine?

loop checking is perform before cable termination..the difference between a close loop and open loop is,tha close loop has a feedback while the open loop has not.


What is the difference between while dowhile?

While: If we can use while statement it will check the condition then proceed further loop statement.DoWhile: If we use dowhile, first execute loop statement then check the condition.


What the difference between pretest loop and posttest loops?

The difference is that pre means before and post means after in Latin so it's tested before or after. :)


What is the difference between while loop and for loop in matlab?

A while loop executes code inside the while block continuously until the said condition is not true. A for loop contains three parts. The first part is carried out prior to the for loop, the middle part is executed by the for loop until it is no longer true, and the final part is performed at the end of each go round of the loop.