Vernier Software and Technology
Vernier Software & Technology

Simplifying with Loops

Introduction

In this activity, students learn to use a loop and a variable to program mBot to make multiple turns. Loops are a common control structure in programming; they increase the efficiency of the coding process and make the code cleaner and easier to read. A variable can be thought of as a container that can hold a information such as numbers or a word. NOTE This activity is designed to follow Activity 3.

Loops and variables can be difficult concepts for students. Loops are used frequently in later activities, so it is worth spending time to ensure that students understand them well. Conversely, variables are only used in a few other programs; it is less important for students to fully understand the concept of variables.

NOTE At the time of release, the "repeat" and "repeat-do" blocks in the mBlock Blockly app are incorrectly labeled "forever" and "forever-do". Fortunately, the "forever" and "forever-do" blocks function in the same way as the "repeat" and "repeat-do" blocks. Direct to students use the "forever" and "forever-do" blocks, and their programs will work as expected. The app developer expects to correct the error in a future release.

Objectives

  • Learn to how to use a loop control structure to perform a repeated action.
  • Create and use a variable to temporarily store a value to be used later.
  • Write an mBot program using the mBlock Blockly app.
  • Practice writing code and troubleshooting when problems arise.

Sensors and Equipment

This experiment features the following Vernier sensors and equipment.

Option 1

Option 2

Additional Requirements

You may also need an interface and software for data collection. What do I need for data collection?

Coding with mBot: Self-Driving Vehicles

See other experiments from the lab book.

C1Manual Drive
C2Obstacle Avoidance
C3Guided Navigation
C4Safety Features
C5Cruise Control
C6Driving Outside the Lines
C7Security and Emergency Systems
C8Autonomous Parking and mBot-to-mBot Communication
C9Changing Lanes
M1Driving mBot
M2Teaching mBot to Drive by Itself
M3Point, Pivot, Swing!
M4Simplifying with Loops
M5Watch the Road
M6Walk the Line
M7Avoiding Obstacles
M8Use Your Lights!
M9Sounds and Security Systems
M10Driving Safely
M11Autonomous Parking
M12Put mBot to Work
M13Give mBot Some Personality

Experiment M4 from Coding with mBot: Self-Driving Vehicles Lab Book

<i>Coding with mBot: Self-Driving Vehicles</i> book cover

Included in the Lab Book

Vernier lab books include word-processing files of the student instructions, essential teacher information, suggested answers, sample data and graphs, and more.

Buy the Book

Go to top