Logic in flows

2 min read

Some special blocks are available to control the flow. This page describes the 'if-statement' block together with the 'loop' and 'aggregate' blocks.

Flows are 'deterministic' in the sense that you cannot connect a block's output to its own input.

Conditions (if-statement)

Within flows, you can use the "If-statement" block to define multiple execution paths. This block has three inputs: a, b, and the operator, which defaults to "=" (equal to). When the condition "a [operator] b" equals true, the flow continues at the "then" output pin and at the "else" pin otherwise. You may also use multiple if-statement blocks to define 'switch' functionality. In that case, you won't use the "else" output pin, as shown in the example below.

If-statement example

Loops

Flows can loop over an array by using the Loop service in combination with Aggregate.

Loop example

An array is provided to the loop service. From there, the flow is executed per array element. In its simplest form, the loop block is directly connected to the aggregate block. This is useful for simple transformations of each element. In the example below, we will convert [{"public":"...","private":...},...] to an array containing only the elements with the key "public".

Loop with only loop and aggregate blocks

The output of the last block within the loop is connected to the item pin of the aggregate block. The aggregate block defines the output of the loop. You provide the output per item in the mapping. The output of the aggregate block will be an array with all these items in the same order as the input for the loop block.

The loop block continues at its empty pin when it receives an empty array. You must connect this pin to continue the flow in this case, otherwise the flow will not get any output and hence trigger an error.

Loops can also have blocks between loop and aggregate. You can use this, for example, to make an HTTP request for each element in the array.

Complex loop example