Programs such as those that operate our air conditioners must repeat until they are stopped by a person. This is also true for the programs of our robots. Here's how to make your program repeat until it meets a condition set by you.

To access the full video please subscribe to FLLCasts.com
- #1629
- 11 Jun 2020
The "while" repeats the code set by him while the condition set by you is true/met.
Here's what this operator would look like in your code:
while condition:
(code that repeats when the condition returns false)
(code that will execute after the end of the loop)
⚠️ Notice the colon after the condition. It's common to forget to place it and students wonder why the program doesn't work!
If you set a condition that will always be met, then the code inside the "while" operator will repeat until you manually stop it. An example of such a condition is "True":
while True:
(code that will execute indefinitely)
(code that will never be reached)
In such a case, the program will indefinitely repeat the code that's within the "while" operator, which is why it will never execute the code after it.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Python with LEGO Mindstorms EV3 - Level 2
In the second level of Python for EV3 robots, students learn in-depth the touch sensor. The sensor is used as an input device for manual control of machines, as well as a sensor for autonomous robots. In a pair of lessons, students build a control panel for the grabber and the movement of a crane. Programming wise, students learn how to fork code with "if-else" constructions, how to create conditional and forever loops with "while" and how to negate conditions with "not" operator. In the end of the lesson, robots can detect obstacles and avoid them, so that they traverse a simple labyrinth.
- 39
- 19:58
- 93

Lesson 2 - Grabber control panel
Introduction
Today we will create a robot that you can control with just tha press of a button. It will detect when you have pressed the button once and when you've pushed it twice. Based on this, it will either open or close its pincers and the objects within.
In this lesson, as well as the next one, we will be building a control console: first for the pincers, later for a crane. We will be looking at the sensors as a means of human interaction with the robots before we make autonomous robots with them.
What aspect of your daily life would you automate?
- 6
- 6
- 7
- 3d_rotation 2