0

What is the method by which a programmer selects the style of loop to use? I have been looking around but I can't seem to get a straight answer. I understand that you can wrangle most looping styles into working for any particular problem, but when I "guess" a good loop, everything just goes well.

My question is...Is there a formal methodology to determine the best type of loop to at least start with?

I'm currently studying Ruby and sometimes not knowing when to enumerate and when to use a more manual loop i.e. a while loop.

Articles, old posts or good books would all be valid answers.

Thanks!

Returnvoid
  • 23
  • 4
  • 2
    https://stackoverflow.com/a/99246/11683? – GSerg Mar 12 '21 at 22:41
  • 1
    Opinion questions are generally discouraged on Stack Overflow. Also, you'll need to specify a language, as languages vary in the types of loops they allow, as well as in their optimizations for speed, memory, and programmer convenience. To answer your question, though, the first step is to understand the differences between the different loops. Usually the reason you want a loop constrains what sorts of types you might use. Try https://www.lynda.com/Java-tutorials/Comparing-different-types-loops/184457/374303-4.html for Java, or search on "compare loop options in X" where X is your language. – Sarah Messer Mar 12 '21 at 22:41

0 Answers0