0
What's the difference between for and while loop? does while loop keep running until the condition is true?
4 ответов
+ 4
Use for loop when you know how many times a piece of code needs to run. And use a while loop when you do not know how many times to run a pice of code. Yes a while loop runs until the condition is false.
+ 2
The main difference between the for's and the while's is a matter of pragmatics: we usually use FOR when there is a known number of iterations, and we use WHILE constructs when the number of iterations is not known in advance. The WHILE vs DO...WHILE issues is also because of pragmatics, the second executes the instructions once at start, and afterwards it behaves just like the simple while.
0
There is no change in if and while loop. The major difference in loop syntax and if loop has else option and nested loop.while has only one sytax and use.while can replace single if statement
- 1
In for loop, initialization, condition and increment or decrement. and while loop will perform the operation if and only if the condition is correct. While loop keep running if condition is true and there is any increment or decrement statement.