answersLogoWhite

0

There is no best loop. All the loops have some special functionality which when used properly will provide great results. Here's my opinion on the three loops:

for and while loop:

These are entry controlled loops. In case of a for loop; initialization, condition and increment/decrement is done together inside the parenthesis. For loops are best suited for purposed where the number of iterations are fixed. In case of a while loop; initialization, condition and increment/decrement are done separately. These are best suited for purposed where the number of iterations are unknown.


do-while loop:

This is an exit controlled loop. Hence it is best suited for purposed where you want a set of statements to be executed despite the loop condition being false.

User Avatar

Wiki User

12y ago

What else can I help you with?

Related Questions

What are two types of iteration?

Two types of iteration are definite iteration (where the number of iterations is known in advance, such as using a for loop) and indefinite iteration (where the iteration continues until a certain condition is met, such as using a while loop).


What are the two types of Iteration?

The two types of iteration are definite iteration, where the number of repetitions is known before the loop starts, and indefinite iteration, where the loop continues until a certain condition is met.


What is a do-while loop?

A while loop evaluates the conditional expression at the start of each iteration, whereas a do..while loop evaluates the conditional expression at the end of each iteration. Thus the do..while loop always executes at least one iteration.


Which Loop avoids check at every iteration?

All loops available in Java (for, while, do-while) have a loop termination condition that would get executed during every iteration of the loop. Without checking the loop condition the loop cannot be terminated and hence avoiding the loop condition check during iteration is not logic and Java does not do it.


What is the difference between dowhile loop dountil?

A do-while loop checks its termination condition before each iteration, including the first; a do-until checks after each iteration, so that the first iteration occurs before the first check. The C language uses the word "while" for both types of loop, using the placement of the condition to control its timing:C do-while:while (condition) { /* condition checked before first loop iteration */... loop contents}C do-until:do {... loop contents} while (condition); /* condition not checked until after first loop iteration */


Each repetition of a loop is known as a?

an iteration.


When is Iteration used in a Java program?

in a loop


How many times does a for loop run in a typical iteration?

A for loop typically runs a specific number of times in each iteration, as determined by the loop's initialization, condition, and increment/decrement statements.


What is while loop?

A do-while loop is a statement or series of statements that are executed at least once. At the end of each iteration, a conditional expression enclosed in a while() statement is evaluated to determine if the loop should start a new iteration or not.


What looping process checks the test condition at the end of the loop?

The do..while() loop tests the condition at the end of the loop. Therefore the loop body executes at least once. The while() loop (without do) tests the condition before entering the loop and before each iteration of the loop. The for() loop conditional expression is optional but, when specified, is tested before entering the loop and before each iteration of the loop.


What is non touching loop?

A non touching loop is where each iteration does not access data from a different iteration. An optimizing compiler/interpreter can detect this, and spread out the loop between different threads, potentially (with multiple processors) running the loop faster. An example of a non touching loop is the addition of two arrays. Each iteration accesses one element, and has no dependencies on elements accessed in different iterations. An example of a touching loop is the summation of elements in an array. Each iteration depends on the result of a different, usually the prior, iteration. Even there, however, the optimization process can spread the work out amongst different threads so long as there are synchronization mechanisms in place.


What are the differences between iterations and loops in progamming?

A loop will loop for n iterations. Each times the program executes the code in the loop is an iteration.