Home > Articles

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.

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.