2
105kviews
Explain difference between for, while and do while loop.
1 Answer
4
17kviews
Sr. No For loop While loop Do while loop
1. Syntax: For(initialization; condition;updating), { . Statements; } Syntax: While(condition), { . Statements; . } Syntax: Do { . Statements; } While(condition);
2. It is known as entry controlled loop It is known as entry controlled loop. It is known as exit controlled loop.
3. If the condition is not true first time than control will never enter in a loop If the condition is not true first time than control will never enter in a loop. Even if the condition is not true for the first time the control will enter in a loop.
4. There is no semicolon; after the condition in the syntax of the for loop. There is no semicolon; after the condition in the syntax of the while loop. There is semicolon; after the condition in the syntax of the do while loop.
5. Initialization and updating is the part of the syntax. Initialization and updating is not the part of the syntax. Initialization and updating is not the part of the syntax
6. For loop is use when we know the number of iterations means where the loop will terminate. While loop is use when we don't know the number of iterations means where the loop will terminate. Do while loop is use when we don't know the number of iterations means where the loop will terminate.
Please log in to add an answer.