Home > Articles

  • Print
  • + Share This
This chapter is from the book

Q&A

Q. Is there any particular reason why I should use one sort of loop over another?

A. It’s true that there is usually more than one type of loop that will solve any particular programming problem. You can use the one you feel most comfortable with, though it’s usually good practice to use whichever loop makes the most sense (in conjunction with your chosen variable names) in the context of what your code sets out to do.

Q. Is there a way to stop the current trip around a loop and move straight to the next iteration?

A. Yes, you can use the continue command. It works pretty much like break, but instead of canceling the loop and continuing code execution from after the closing brace, continue cancels only the current trip around the loop and moves on to the next one.

  • + Share This
  • 🔖 Save To Your Account