Skip to main content
LessonGrades 4 - 7

How Do You Make Loops and Switches?

Photo shows a girl lying on the floor, working on a laptop computer. A diagram with the words "I am in a loop!" surrounded by a blue oval-shaped ring with four red arrows pointing in a counter-clockwise direction.Students learn how to program using loops and switches

Students learn how to program using loops and switches. They see how loops enable us to easily and efficiently tell a computer to keep repeating an operation. They also see that switches permit programs to follow different instructions based on whether or not preconditions are fulfilled. Using the LEGO® MINDSTORMS® robots, sensors and software, student pairs perform three mini programming activities using loops and switches individually, and then combined. With practice, they incorporate these tools into their programming skill sets in preparation for the associated activity. A PowerPoint® presentation, pre/post quizzes and worksheet are provided.

Loops and switches are important programming components in any language. Loops are important because nearly every computer program must iterate operations many times in order to complete tasks. Indeed, performing tedious operations repeatedly was one of the foremost motivations for the invention of the computer. Switches are almost equally important; they enable programs to accommodate a variety of situations. Further, switches in the LEGO MINDSTORMS NXT programming environment are used similarly to "if/else...then" statements, which are used in other more common programming languages.

After this lesson, students should be able to:

  • Explain what loops and switches are and identify programming situations in which loops and switches should be utilized.
  • Write programs that incorporate loops and switches.

More Like This