One in which the condition is evaluated at the beginning. Details vary from language to language; for example in Java, this may be the case both with a for loop and with a whileloop.
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
Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
Generally speaking a for loop looks like this:for(Initialization;condition;increment){Do Stuff}whereas a while loop looks like this:while(condition){Do Stuff}Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.
Counter Loop:Counter loop is a loop which executes statement up to a fixed number of time.In GW FOR ... NEXT loop is used as counter loop.Controlled Loop:Controlled loop is used to extend the statements till a specific condition is satisfied. In GW WHILE ... WEND is used as controlled loop.
Repeat until loops run until a condition is true. They repeat at the end of the loop and they will always run at least once. While do loops will only run while a condition is true. They may not run at all.
Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.
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
Java has three kinds of loops 1. For Loop 2. While Loop 3. Do - While Loop Both For loop and While loop would iterate through a certain lines of code within the loop's limit as long as the loop condition is satisfied. A do while loop would execute the loop once even before checking the condition. So in a do while loop, even if the loop condition is not satisfied the loop would execute once. Example Declarations: for(int i = 0; i < n; i++) { ..... } while (i < n) { ... i++; } do { ... i++; } while (i < n) ;
C has 3 types of loops. do { foo += increment; } while(foo != bar); This loop will continue until foo equals bar but will execute the loop at least once, even if foo equals bar. The variable increment may be changed within the do loop. It is imperative that the value foo can reach equality with bar, otherwise an endless (run for ever) loop condition exists. ***** while(foo != bar) { foo += increment; } The loop will continue until foo equals bar but will not execute if foo equals bar. The variable increment may be changed within the do loop. It is imperative that the value foo can reach equality with bar, otherwise an endless (run for ever) loop condition exists. ***** for (foo = 0; foo < bar; foo+= increment) { } The loop will continue until foo equals bar. The stepping amount is controlled by the value of increment. The value of increment could be changed inside the loop.
Generally speaking a for loop looks like this:for(Initialization;condition;increment){Do Stuff}whereas a while loop looks like this:while(condition){Do Stuff}Before the while loop there should be some initialization and somewhere in the Do Stuff section there should be statements that change the condition. Those statements are analogous to the increment section of the for loop.
Counter Loop:Counter loop is a loop which executes statement up to a fixed number of time.In GW FOR ... NEXT loop is used as counter loop.Controlled Loop:Controlled loop is used to extend the statements till a specific condition is satisfied. In GW WHILE ... WEND is used as controlled loop.
Repeat until loops run until a condition is true. They repeat at the end of the loop and they will always run at least once. While do loops will only run while a condition is true. They may not run at all.
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--; }
The least possible is no iterations: for (x=0; x<max; ++x) { // ... } In the above example, if max is less than or equal to zero then the body of the loop will not execute.
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.doCONTENTwhile(CONDITIONS);The WHILE loop goes back to the DO if the conditions are matched. The DO happens without any conditions.:) :) :)
For loop is "Counter controlled loop" i.e. a counter or control variable is used to process the for loop , as discussed in earlier chapters.For loop is an "Entry controlled loop" i.e. the condition to iterate the loop must be check at the starting of the loop and loop body will not execute if the condition is False. Source website:http://codedunia.in/c-language/for-loop-in-c-programming.php
An infinite loop.