Java Child / The Four Moves Everything Is Built From
Repeating Without Losing Track Of Where You Are
Repetition is the third move, and it demands two questions that beginners often forget to ask.
Doing something repeatedly is what makes a machine worth the trouble. The idea is simple and the failure modes are not. Every repetition needs an answer to two questions: what changes on each pass, and what condition eventually makes it stop. If nothing changes, the repetition never ends. If the stopping condition can be stepped over rather than landed on, it may never end either. Both failures feel dramatic when they happen and both come from the same source, which is thinking about the body of the repetition without thinking about its arithmetic.
There is a second, quieter class of error, involving the boundaries. Repetitions that run one time too many or one time too few are extraordinarily common, and they are common because the human mind counts things naturally in a way that does not always match how a machine steps through them. The cure is not cleverness, it is checking the ends explicitly. What happens on the very first pass. What happens on the very last. What happens when there is nothing to repeat over at all.
Think of a repetition as a promise you renew each time around. Before each pass, something is true. The pass does its work and, when it finishes, that same something is true again, with the situation moved one step closer to the finish. If you can state that promise in a plain sentence, you understand the repetition. If you cannot, you are hoping, and hope produces instructions that work on the examples you tried and fail on the ones you did not.