no difference in logic in both of them you put the key to enter :while( ....),for(;....;)
but infor loop you have option to initialize value and make operation on it
for(int i=0;...;i++){} same int i=0; while(..){ i++;}
first be sure what u r asking? if just u mention it as loop what shall i take is tat for loop,do while? while first check the condition and then start execute the comming steps.but do while ll start the coding and then check for the condition. Rgds, BM
The while statement loops until the expression is false. If the expression is false to start with, the statement never executes, not even once. The expression is evaluated the first (and subsequent) times - if it has side effects, then they apply even if the expression is false to start with.
It is also called as pretest loop.It executes the block of code after evaluation of condition in while statement.If evaluated answer is true,it will executes the block of code otherwise it will quit the loop.
The while loop will check the condition and then execute the body of loop. In the do-while loop the body is executed first and then the condition in while is checked. The advantage of the do-while loop is where you want to execute the body of while atleast once.
The do-while loop is a looping structure. This looping structure is an exit controlled loop. that means the loop executes at-least once before the test expression is checked.
The general form of do-while loop is:
do
{
statement1
statement2
}
while (expression)
according to my view for loop is best,because in FOR loop assign values,condition and update write in single line.it overcomes syntax error.
It's like fruit (loop) and apple (do-while loop).
post - iterative
If you want to execute a statement which is in while loop at least one time you can use do- while loop. this is why because initially first statements will be executed then condition will be checked. but in case of while first condition will be check then statements will be executed
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
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.
ComparisonThe conditions for both the 'while' and 'for' loop are exactly the same, but in each flow structure the conditions are placed in different locations. A 'for' loop places the full condition within the 'for' loop whereas the 'while' loop places the counter variable outside of the loop.The 'for' loop is used when the length of the loop is known whereas the 'while' loop is usually used when the length of the loop is unknown.'for' loop exampleWithin the parentheses the complete condition is contained. The condition has 3 parts delimited by a colon ';'. The first part sets the counter 'int i' to 0, the second part tells the loop to stop when the counter is 5. The third part tells java to increment the counter by 1 value each time the loop iterates.for ( int i = 0; i < 5; i++)'while' loop exampleWith the 'while' loop the counter is initialized outside of the 'while' loop. Inside the parentheses of the loop the condition is set to stop looping when the counter reaches a value of 5. Inside of the 'while' loop block the counter is set to increment by 1 value each time the loop iterates.int i = 0;while ( i < 5 ) {i++}
Body of the loop
You mean PL/SQL? Well, they are different things, read the manual for details.
If you want to execute a statement which is in while loop at least one time you can use do- while loop. this is why because initially first statements will be executed then condition will be checked. but in case of while first condition will be check then statements will be executed
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
the counter variable cannot be initialized in while loop before entering into the block.
Tadpole has two chambered heart and a single-loop system while the adult has a three chambered heart and a double-loop system
Sure. Here is an example: for (i=0; i<3; ++i) printf ("I am for loop, i=%d\n"); i=1; while (i>0) { printf ("I am while loop, i=%d\n"); i <<= 1; }
Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.
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.
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.
Well 'while' goes like this: while (condition) statement 'for': for (initialize; condition; after-each-loop) statement
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
The do ..while loop is executed at least once, whereas the while loop may not be executed even once.