You have been using a simple form of the for loop since Chapter 1. You might be surprised at just how powerful and flexible the for loop is. Let’s begin by reviewing the basics, starting with the most traditional forms of the for.
The general form of the for loop for repeating a single statement is
Ask the Expert
Q: Under what conditions should I use an if-else-if ladder rather than a switch when coding a multiway branch?
A: In general, use an if-else-if ladder when the conditions controlling the selection process do not rely upon a single value. For example, consider the following if-else-if sequence:
This sequence cannot be recoded ...