Chapter 03 Conditions, Time & Loops
#025 For Loop with Break
Five chests. The third one holds the key. So why search the last two?
- 1:14 video
- Written lesson
- Beginner
Free for everyone from 28 Oct 2026, 00:00 CET
Stopping early
A normal For Loop runs every index. It can’t stop early. For Loop with Break can.
It has the same First Index, Last Index, Loop Body and Index pins. The new part is Break, an execution input. Call Break from inside Loop Body, and no further iterations run. Then Completed fires, just like after a full loop.
Example: the chest search
First Index 0, Last Index 4. Loop Body calls a Branch whose condition asks: does this chest have the key?
Chest 0: false. Chest 1: false. Chest 2: true, and True calls Break. Chests 3 and 4 are never checked. Then Completed fires once, so open the door there.
The same pattern finds the first free inventory slot, or the first enemy in range.
Completed can’t tell you why
Completed fires after a break and after a full loop, so on its own it can’t tell you if the key was found. Set a Found Key boolean before calling Break, and check it after Completed.
Common mistakes
- Wiring Break to False stops the loop at the first chest without the key.
- Like every loop, it still runs inside one frame.
In short
Break skips the rest. Completed still fires.
Covered in this lesson
- For Loop with Break
- Break
- First Index
- Last Index
- Loop Body
- Index
- Completed
- Branch