So far you have used the loop block to infinitely repeat your programs. Did you know that a program can be repeated until a condition evaluates to true without having to use the loop interrupt block?

To access the full video please subscribe to FLLCasts.com
- #1102
- 08 Feb 2019
By clicking on any of the ends of the loop block, we select it and we can see its settings in the lower part of the window:
Similarly to the wait block which waits until a command is given, the loop block repeats the blocks in its body until the condition for exiting the loop is met.
What exiting conditions are there? There are five types of cycles in EV3 which differ according to the duration of repeating the cycle body. We can see them if we click on the drop-down menu located on the right of the Control button.
1. Forever – this is the setting by default. If chosen, the cycle body will repeat infinitely. If there are blocks after this cycle, they will never be performed! When we have such a cycle, the robot should be manually stopped by the light grey button.
2. Sensor – when choosing this setting, the body cycle will repeat until any of the sensors detects a certain value. We will focus on that setting in the next levels.
3. Time – when choosing this setting, the cycle will repeat for a definite period of time which is set in seconds.
4. Count – this is one of the settings frequently preferred. It allows us to choose how many times the cycle body will be repeated. To make the robot move in a square we will use this exact setting and will set it to 4.
5. Logic – this setting is more complex and won’t be used at this stage of training.
The following example shows how to set the loop block so that the program is repeated until the motor attached to port A turns more than 90 degrees:
As you can see, the conditional loop block can work with all the sensors you have access to.
Remember that the condition is actually a loop interrupt condition. The loop will execute a block of statements repeatedly, until a given condition evaluates to true. When the condition evaluates to true, the next block in the program will be executed.
Important: the condition will be evaluated only once per repetition (iteration) of the loop, after all blocks of the loop body are executed. If you insert a wait block into the loop, you may witness some unexpected behavior.
Courses and lessons with this Tutorial
This Tutorial is used in the following courses and lessons

Robotics with LEGO - Level 3.0 - Security systems
This is the fifth level of the Robotics with LEGO curriculum for students in fifth to twelfth grades.
In this level students will learn how to work with data measured by the sensors. The concept of Algorithm is introduced and the programs perform calculations without knowing the values beforehand. The programming blocks transfer data between each other via data wires. The robots are designed to address the problems of security systems. Variety of alarm systems are built and the physical principles of different security methods are considered.
- 50
- 1:03
- 213

Lesson 4 - Seismic sensor
Introduction
In the following two lessons you will be the chief prison guard. Rumor has it that a gang of cake robbers is to be moved to your prison and they are planning to escape. In order to avoid a public scandal, the Mayor of the city has decided to invest in a new security system for the prison. Your job is to preserve the good name of your prison and protect the cakes in all pastry shops in the area.
- 5
- 11
- 7
- 3d_rotation 1

Instructors Remote Training
If you are working with students and you want to introduce Robotics to your class or you want to mentor a FLL team, but you are insecure about your technical knowledge in the Robotics field, then this is the right place for you. Having in mind teachers' busy schedule, we have design two different schedules and added an option to design one just for you. FLLCasts's Mindstorms EV3 Robotics Online Training is the perfect match for any teacher.
After the completion of each task the participant has to upload his solution for verification.
- 136
- 280:11
- 156

Robotics with LEGO - Level 3.0 - Security systems
This is the fifth level of the Robotics with LEGO curriculum for students in fifth to twelfth grades.
In this level students will learn how to work with data measured by the sensors. The concept of Algorithm is introduced and the programs perform calculations without knowing the values beforehand. The programming blocks transfer data between each other via data wires. The robots are designed to address the problems of security systems. Variety of alarm systems are built and the physical principles of different security methods are considered.
- 50
- 1:03
- 213