0

While and For loops

what's the purpose of for loop when we have while loop? is there any specific task one loop can do that the other cannot do?

9th Oct 2017, 5:28 PM
Vamsi Mohan Ramineedi
Vamsi Mohan Ramineedi - avatar
2 Respostas
+ 2
They are interchangable. The only difference is the syntax. You can do anything even with a simple goto, though the resulting code readability will be bad. Usually it's a good idea to use for loop, whenever a counter should be introduced, and while loops when a block of code should be executed literally 'while' some condition is true.
9th Oct 2017, 5:37 PM
deFault
0
thanks
9th Oct 2017, 5:38 PM
Vamsi Mohan Ramineedi
Vamsi Mohan Ramineedi - avatar