answersLogoWhite

0

Do while loop uses

Updated: 8/11/2023
User Avatar

Wiki User

13y ago

Best Answer

The DO WHILE loop is like the WHILE loop very much, except for one thing. The WHILE loop is like an IF loop but it keeps on going. The WHILE loop needs to start, so the beginning, when you are setting the conditions, is exactly the same. When the WHILE loop is done, it goes back to right before the conditions. The DO WHILE loop starts the WHILE loop so that you can have a WHILE loop that does not start with conditions, but instead, needs conditions to keep on going. This might not be the exact syntax, because if it doesn't work try it without the semicolon after the while. And anyways, if that doesn't work, I started with C++, not C.

do

CONTENT

while(CONDITIONS);

The WHILE loop goes back to the DO if the conditions are matched. The DO happens without any conditions.

:) :) :)

User Avatar

Wiki User

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

Wiki User

15y ago

A do-while loop is a control structure that contains code that will execute based on a condition. Do-while loops are 'post-test' loops which mean that they execute the code that they contain before testing the condition.

Pseudocode:

do

{

Insert Code to execute here

}(Insert Condition to be met here);

This is what a C++ loop may look like. In here the curly brackets("{,}") contain the code that is to be executed. And the parenthesis("(,)") contain the conditional.

The loop will execute the code, and THEN test the conditional, which means that a do-while loop will ALWAYS run ONE time through the code.

For instance, you want to output something to a command console like a basic menu.

do

{

print("1:Start");//print menu to the screen

print("2:Stop");

print("3:Exit");

input(integer);

//test the value of integer

//call appropriate functions

}(If the user enters a number other than 1, 2, 3);

This loop will output the menu, and until the user enters a valid response keep outputting the menu. Do-whiles are useful if you know that the code needs to be executed once, if the code may never need to be executed you might use a typical while loop or a for loop.

This answer is:
User Avatar

User Avatar

Wiki User

12y ago

The do loop is similar to the while loop, 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.

This answer is:
User Avatar

User Avatar

Wiki User

13y ago

A Do While loop is used in cases where you want the loop code block to execute atleast once, irrespective of whether the loop condition is satisfied or not.

for ex:

int i = 0;

do {

...

...

//lots of code

} while (i > 0)

Though the value of i does not match the condition in the while block, the code inside the do .. while braces ({}) will get executed once.

This answer is:
User Avatar

User Avatar

Wiki User

11y ago

Forenoon.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Do while loop uses
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What type of loop uses a boolean expression?

A "while" loop is appropriate in this case - one in which the condition is evaluated at the beginning of the loop.


Which pair of loops causes a statement or set of statements to repeat as long as a condition is true?

A while loop repeats until the condition becomes false, and may never execute: int a = 4; while (a > 5) { //Do something } or int a = 4; while (a > 0) { //Do something a--; }


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 type of loop uses Boolean expression to control the number of times that it repeats a statement set of statements?

A counted loop. Typically we use a for loop for counted loops: // loop 10 times... for (int i=0; i<10; ++i) { // ... } We can also use while and do-while loops to do the same thing, however a for loop provides all the information up front where it belongs and we can localise the control variable. With while and do-while loops, the control variable must be declared outside the loop, and the increment is usually specified at the end of the loop. This makes while and do-while loops harder to read because the information that controls the loop is separated: // loop 10 times... int i = 0; while (i<10) { // ... ++i; } A do-while loop is similar to a while loop, but the control expression is placed at the end of the loop thus the loop always executes at least once. This also upsets the logic of a counted loop because the control variable is off-by-one. // loop 10 times... int i = 0; do { // ... ++i; } while (i<11);


What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop

Related questions

For loop -uses?

You can use a for loop whenever you can use a while loop; it's the same.


What type of loop uses a boolean expression?

A "while" loop is appropriate in this case - one in which the condition is evaluated at the beginning of the loop.


What are while loop in vb.net?

The while loop in vb.net uses the syntax form which provides a way to continue iterating while one or more conditions are true.


What is a nested loop in java?

A nested loop is a (inner) loop that appears in the loop body of another (outer) loop. The inner or outer loop can be any type: while, do while, or for. For example, the inner loop can be a while loop while an outer loop can be a for loop.


What are the similarities of while loop and a do while loop?

They both loop


Which pair of loops causes a statement or set of statements to repeat as long as a condition is true?

A while loop repeats until the condition becomes false, and may never execute: int a = 4; while (a > 5) { //Do something } or int a = 4; while (a > 0) { //Do something a--; }


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 HDMI loop output means?

The HDMI loop through function allow an operator to shoot with primary monitor while another uses a second monitor simultaneously.


The while loop is a type of loop?

Is loop


What type of loop uses Boolean expression to control the number of times that it repeats a statement set of statements?

A counted loop. Typically we use a for loop for counted loops: // loop 10 times... for (int i=0; i<10; ++i) { // ... } We can also use while and do-while loops to do the same thing, however a for loop provides all the information up front where it belongs and we can localise the control variable. With while and do-while loops, the control variable must be declared outside the loop, and the increment is usually specified at the end of the loop. This makes while and do-while loops harder to read because the information that controls the loop is separated: // loop 10 times... int i = 0; while (i<10) { // ... ++i; } A do-while loop is similar to a while loop, but the control expression is placed at the end of the loop thus the loop always executes at least once. This also upsets the logic of a counted loop because the control variable is off-by-one. // loop 10 times... int i = 0; do { // ... ++i; } while (i<11);


What is a loop type?

A Loop is a programming language construct that instructs the processor to repeat a sequence of operations a number of times until a specific condition is reached. There are different types of loops. They are: * for loop * while loop * do while loop


Why you need a for loop when you have already while loop or do while loop?

We need a for loop because the while and do-while loops do not make use of a control variable. Although you can implement a counter inside a while or do-while loop, the use of a control variable is not as self-evident as it is in a for loop. Aside from the use of a control variable, a for loop is largely the same as a while loop. However, it is quite different to a do-while loop, which always executes at least one iteration of the loop before evaluating the conditional expression. In a for and while loop, the conditional expression is always evaluated before entering the loop, which may result in the loop not executing at all.