defferentiate between 'for' loop and a 'while' loop in long answer
Answers
Answered by
0
Answer:
- Initialization, condition checking, iteration statement are written at the top of the loop. Only initialization and condition checking is done at the top of the loop.
- The 'for' loop used only when we already knew the number of iterations. The 'while' loop used only when the number of iteration are not exactly known.
- If the condition is not put up in 'for' loop, then loop iterates infinite times. If the condition is not put up in 'while' loop, it provides compilation error.
- In 'for' loop the initialization once done is never repeated. In while loop if initialization is done during condition checking, then initialization is done each time the loop iterate
- In 'for' loop iteration statement is written at top, hence, executes only after all statements in loop are executed. In 'while' loop, the iteration statement can be written anywhere in the loop
HOPE THIS HELPS YOU❤ ☺
Answered by
2
Answer:
The 'for' loop used only when we already knew the number of iterations. The 'while' loop used only when the number of iteration are not exactly known. If the condition is not put up in 'for' loop, then loop iterates infinite times. If the condition is not put up in 'while' loop, it provides compilation error.
Similar questions
Math,
1 month ago
Social Sciences,
1 month ago
Social Sciences,
2 months ago
Social Sciences,
2 months ago
Math,
9 months ago
Hindi,
9 months ago