← Back to X_TRADER® Help Library

#### Loop Block

##### Operations

The Loop Block simply generates and outputs a user-specified number of empty discrete event messages, one after another, in order to facilitate designs which require loops.

1. The user must specify the total number of discrete event messages to be generated as .
2. When a discrete event message, , triggers the Loop Block, the block will update its output to "1" and then output its first discrete event message .
3. The Loop Block will increment its by 1, and then generate its second discrete event message . This step will repeat until is greater than .
4. After the last message is generated, the Loop Block will generate and output another discrete event message to indicate that the loop sequence has been completed.

Note:The will always update first before the actual message is generated and output.

##### Details on Timing

It is important to note that the Loop Block does not allow any “actor” block (i.e., a block that can take tangible actions such as placing an order) to take an action while it is performing the loop. For a list of actor blocks, refer to Actor Blocks.

Example: Loop Block Timing

In this example, the Loop Block is designed to loop up to three times, and at each iteration it decrements the price input of the Order Block by one price increment. At a glance, it might seem that the Order Block will generate three change requests to incrementally move its child orders down the market. However, the Loop Block does not allow the Order Block to take any actions during the loop. It is only after the loop has completed that the Order Block can take an action using the final resulting price input.

The following sequence of events occurs when this algorithm is started:

1. The Order Block joins the best bid price with a 1-lot child order.
2. The Generator Block generates and pushes a discrete event message downstream, triggering the Loop Block.
3. The Loop Block loops up to three times, and at each iteration it decrements the price input of the Order Block by one price increment. However, the Order Block cannot take any action during this step.
4. After the loop completes, the Order Block changes its child order based on the final resulting price input.