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.
if is an conditional non iterative statement but while ia an conditional iterative statement
No such thing as 'if-loop', you can choose from:while (expression) statementfor (expression; expression; expression) statementdo statement while (expression)
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 for loop is defined with an boolean expression to indicate when it should terminate. A for each loop iterates once for each item in a collection. for example, "for each (book in bookshelf)" will iterate once for each book on the bookshelf, providing access to the current book. a for loop is defined like "for (int i = 0; i<10;i++)" meaning the loop will iterate as long as the condition is true (i < 10), and will increment on each loop. Note: there is no 'for each' loop in C language, but there is a 'foreach' in PHP.
Body of the loop
No such thing as if-loop. if-else statement is not a 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.
The do ..while loop is executed at least once, whereas the while loop may not be executed even once.
In short, a for loop declares an variable and assigns it a value, has an argument, and has an update. A while loop only has an argument. More Detail... in C++, which is very close to C an example while loop is; while(i
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
while- It will wrok only if the condition is correct if not it wont excute the body of the loop do-while: In some cases we want that body of the loop and the condition may fails so the loop want to print so the do while loop first excute body of the loop and next it checks the condition it continues until the condition becomes false
A loop will loop for n iterations. Each times the program executes the code in the loop is an iteration.
how do we use loops in c plus plus programing and what are basic differences between do,for and while loop
For Loop:1.In this first it initialized with the starting value such as I=0,count=0.The value which was initialized is then checked with the given test condition. While Loop:1.In this it checks the condition first. for Loop:2.In this we initializ,check conition and increment or dicrement in one statement While loop2:In this only we can test the condition in one statements. For Loop3:general Format: for (initialization; test condition; increment) { body of the loop } While loop:3.general Format while(test condition) { body of the loop }
the counter variable cannot be initialized in while loop before entering into the block.
Both For and While loops are available for the purpose of executing a piece of java code repeatedly until a particular condition is met. The only difference being - the loop condition/counter has to be modified inside the while loop every time whereas the condition is integrated in the for loop definition. Otherwise both the loops are exactly same in all aspects.
Both are programming commands. A do/while loop will execute at least once. A while loop may not execute at all.
A for loop is classified as an iteration statement. A simple example might be... For x = 1 To 10 'loop body Next x The same loop expressed as a while loop (classified as a control flow statement) could be... x = 0 Do While x < 11 'loop body x = x + 1 Loop .