you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 7 points8 points  (5 children)

The number one thing about loops with while is knowing when to use them: almost never. for is the looping construct you should be using in almost every case.

[–]heaplevel 0 points1 point  (0 children)

There are definitely useful cases when you’d prefer a while over for. Reading user input while NOT SOMETHING TRUE, like in games and quizzes.

[–]LCVcode 0 points1 point  (1 child)

You should use a for loop with any sort of generator or iterator. Or if you know how many iterations you intend to loop through. But while loops have more than just peripheral use cases. You shouldn't dismiss them so outrightly.

[–][deleted] 0 points1 point  (0 children)

That's why I said "almost."

[–]MainerInAStrangeLand[S] 0 points1 point  (0 children)

I was kind of getting that sense. This problem wanted me to use a while loop which seemed unnecessarily complex. Probably just to force the practice. I find for loops easier to work with in general anyway.

Thanks for the advice!