0

What's the difference between for and while loop? does while loop keep running until the condition is true?

9th Oct 2015, 2:47 PM
Shashwat Pandey
Shashwat Pandey - avatar
4 Respostas
+ 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.
22nd Oct 2015, 1:50 PM
BitVX
BitVX - avatar
+ 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.
8th Mar 2016, 6:49 PM
chris
chris  - avatar
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
2nd Mar 2016, 10:19 AM
jagadam dinesh reddy
- 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.
20th Feb 2016, 10:00 AM
Rakesh Purohit
Rakesh Purohit - avatar