+ 3

It seems to me that a lot of for loops could be written as while loops, and vice versa.

It seems to me that a lot of for loops could be written as while loops, and vice versa.

4th Dec 2016, 7:38 AM
Lord Centillion
Lord Centillion - avatar
2 odpowiedzi
+ 5
Well yes that is true, but ideally each shine at something. Generally speaking you would use a while loop when you don't know how many iterations are needed you simply know it needs to repeat. On the contrary you have for loops, which are to be used when you know the amount of iterations needed or is working with data structures like an array via enhanced for loop.
4th Dec 2016, 9:01 AM
Don
Don - avatar
0
I agree. Say if you were in a bad situation, you'd want the option to break; it off and return something one can reuse.
5th Dec 2016, 3:33 AM
Allan
Allan - avatar