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?
3 Answers
+ 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.
0
thanks