Sometimes the tasks you wish your robots to perform can have different solutions depending on weather, environment and other conditions.

To access the full video please subscribe to FLLCasts.com
- #1625
- 04 Jun 2020
Example:
Have you ever forgotten where you've left your phone?
If you've forgotten where you've put your phone, you would start checking where you have been and if the phone is there. During all of this, you are constantly doing the following checks:
- If my phone is here, I stop searching.
- If my phone isn't here, I keep searching.
Such tasks require us to program the robot to perform checks and make decisions based on them.
The "if" logical operator allows us to program our robot to perform its actions based on rules set by you.
For it to know what it's doing, the "if" operator requires a condition or statement that can be "True"/met or "False"/unmet to be given.
Here's how this command should look in your code:
if condition: (conditionally executed code) (code that will always be executed)
⚠️ Notice the colon right after the condition. It's common to forget to put in this colon in the beginning and for the students to wonder why the program doesn't work!
If the condition is met or "True", the program will execute the lines of code that are indented inward. If the condition is not met or "False", those lines will be skipped in the execution. There is no difference between indenting with several spaces or a TAB, so long as it is the same throughout the whole program.
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 1 - Security system.
Introduction
In this lesson, we will create a system that checks if the exit of a supermarket is closed or if there are still more people in the building. In big supermarkets, security guards must reassure that all of the clients have left the premises before they've locked the door.
However, there is always the odd case of someone getting locked in by accident, which is why there are security systems that notify the security guards they have made a mistake.
- 5
- 5
- 10
- 3d_rotation 1