Chapter 4. Loops

Introduction

A loop repeats a whole program or part of a program. Once the microcontrollers have entered a loop, they read the instructions in the loop over and over again, repeating the actions programmed within the loop. They exit at the end of the loop only when a given condition applies. We find the same sort of thing in a musical score (Figure 4.1).

Figure 4.1. This musical score is an example of a loop that is repeated once. The two pairs of dots on the right tell the musician to go back and play part of the score again. By contrast, a loop block usually repeats more than once, perhaps many times or even “forever.”

Get Programming Lego Mindstorms NXT 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.