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:

ModeDescription
COUNTRepeat a fixed number of times
TIMERepeat for a fixed duration

COUNT Mode

FieldDefaultDescription
Iterations1How many times to execute the loop body. Can be a fixed number or a variable reference.

TIME Mode

FieldDefaultDescription
Run For60Maximum time the loop runs before exiting via the DONE path
UnitSecondsSeconds, Minutes, or Hours

Section 2: Interval (Timing)

FieldDefaultDescription
Interval1Time to wait after each iteration before starting the next
UnitSecondsSeconds, Minutes, or Hours

Example: A loop with Count: 10, Interval: 5sec reads 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.

FieldDescription
VariableThe variable to check (e.g., current_ph)
OperatorComparison: ==, !=, >, <, >=, <=
ValueTarget 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:

OptionEffect
StopStops the entire flow
PausePauses the flow
ContinueExits via DONE path and continues normally (most common)
Jump to LabelJumps 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.