External Iteration Is Error Prone

Most Java programmers are comfortable with external iteration. However, there are several opportunities for error. For example, you could initialize variable sum incorrectly, initialize control variable counter incorrectly, use the wrong loop-continuation condition, increment control variable counter incorrectly or incorrectly add each value in the array to the sum.

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.