Loop Block
The Loop block repeats a sequence of blocks multiple times or for a set duration. It can also stop early when a condition is met.
How It Works
The loop has two exit paths:
- LOOP (right, purple 🔄) — connect to the blocks that form the loop body. The last block in the body MUST be a Loop Back block that returns to this loop.
- DONE (left, green ✅) — connect to what happens after the loop finishes.
┌──────────┐
│ LOOP │ ◄──────────────┐
│ 5x / 30s │ │
└──┬───┬───┘ │
DONE │ │ LOOP (body) │
│ ↓ │
│ [Sensor Read] │
│ ↓ │
│ [Actuator Set] │
│ ↓ │
│ [LOOP BACK → Loop] ───┘
↓
[Next block]
Important: The Loop Back block at the end of the body is required. Without it, the loop can’t iterate and the flow will be saved as invalid.
Configuration
Section 1: Conditions (Limit Mode)
Choose how the loop knows when to stop:
| Mode | Description |
|---|---|
| COUNT | Repeat a fixed number of times |
| TIME | Repeat for a fixed duration |
COUNT Mode
| Field | Default | Description |
|---|---|---|
| Iterations | 1 | How many times to execute the loop body. Can be a fixed number or a variable reference. |
TIME Mode
| Field | Default | Description |
|---|---|---|
| Run For | 60 | Maximum time the loop runs before exiting via the DONE path |
| Unit | Seconds | Seconds, Minutes, or Hours |
Section 2: Interval (Timing)
| Field | Default | Description |
|---|---|---|
| Interval | 1 | Time to wait after each iteration before starting the next |
| Unit | Seconds | Seconds, Minutes, or Hours |
Example: A loop with
Count: 10, Interval: 5secreads a sensor 10 times, waiting 5 seconds between each read. Total time ≈ 50 seconds.
Section 3: Stop Condition (Optional)
An optional early-exit condition. Checked after each iteration — exits early if it’s met.
| Field | Description |
|---|---|
| Variable | The variable to check (e.g., current_ph) |
| Operator | Comparison: ==, !=, >, <, >=, <= |
| Value | Target value — fixed number or variable reference |
Important: The stop condition means “Keep Looping While” — the loop continues while the condition is TRUE and exits when it becomes FALSE.
Example:
- Variable:
current_ph, Operator:<, Value:6.5 - Meaning: Keep looping while pH is below 6.5. Once pH reaches 6.5 or above, exit the loop.
This is powerful for “dose until target” patterns:
LOOP (count: 20, interval: 30s, stop when: current_ph >= 6.5)
├── Sensor Read → current_ph
├── Actuator: pH Up Pump → DOSE 2mL
└── (back to loop)
DONE → Log "pH target reached"
Error Handling
The loop block’s On Failure controls what happens when the maximum iterations/timeout is reached without the stop condition being met:
| Option | Effect |
|---|---|
| Stop | Stops the entire flow |
| Pause | Pauses the flow |
| Continue | Exits via DONE path and continues normally (most common) |
| Jump to Label | Jumps to a label block |
Troubleshooting
Loop runs forever
- Make sure the loop body connects back to the loop’s input handle via a LOOP_BACK block
- Ensure COUNT or TIME limit is set
- If using a stop condition, verify the variable is being updated inside the loop body
Loop exits immediately
- Check if the stop condition is already met before the loop starts
- Verify the COUNT is not 0
“No loop nodes” in LOOP_BACK target
- LOOP_BACK targets only loop-type blocks. Make sure a loop block exists in the flow.