+ 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.
2 ответов
+ 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.
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.