Skip to main content
A logic.for counts. Each time the flow enters it, it moves a counter one step and sends the flow down next, to run the loop body again, or complete, when the count is done. It holds no body of its own: the body is the steps after next, and a loop is made by wiring the last of them back to the logic.for (Wiring a loop).

How it counts

On each entry the logic.for reads current, decides the route, and writes current + step to the output current. It posts a component.output event, Loop step status: from (0) to (3) step (1) current (-1).
  • next while the counter is short of to. With a positive step, next is taken while current is below to - step. With a negative step, while it is above to - step. Otherwise the route is complete.
  • The body sees the value the counter just reached. The output current is written on every entry, complete included, so a body that reads it sees from, from + step, and so on, and never to. The flow after complete sees to, or the first value past it when step does not divide the range.
  • A fresh counter starts one step early. With no value in current, the counter is taken as from - step, so the first entry writes from. A counter that already holds a value, such as a 0 the editor wrote, starts from that value instead.
  • It counts the way range(from, to, step) does. from 0 to 3 runs the body for 0, 1 and 2. from 3 to 0 with step -1 runs it for 3, 2 and 1.

Wiring a loop

The counter has to survive between entries, so current is wired to a data.integer with the execution persistence (Persistence), once as an input and once as an output, both with the route current. The data.integer holds the value the logic.for wrote last, and its inline value is what the first entry reads. A current port that is wired, or holds a value, satisfies both the input and the output. The flow is a cycle: the logic.for’s next leads to the body, and the last step of the body leads back to the logic.for’s flow input. A connection back is a normal connection. To jump to an earlier step from the middle of the body, use a flow.goto.

When it fails

A logic.for whose from, to or step reads empty at run time, such as one a data component has not yet written, takes failure, and posts no event. A definition that leaves any of the five required ports empty fails its check with Port `<route>` (category: `<category>`) is required.

Example

Ostrava Pumps sends a reminder for each of the three open service requests. A data.integer called Round holds the counter, with the inline value -1 and persistence execution, so the first entry writes 0. The logic.for has from 0, to 3 and step 1; current is wired to Round twice, as an input and as an output.
The reminder step reads Round to learn which request it is on. The summary step runs once, after the third round.