Loop

Go over each element in a collection and do something with it.

When to use?

If you have an array of items, or any other collection that can be traversed, and you want to perform an operation with each item, use this element.

How to use:

  1. Make sure you've got an indexed array obtained with e.g. an Http Client, a Json Reader, or set manually with Set Parameter.
  2. In the Items field, enter the name of the array wrapped in the expression syntax, for example ${array_name}
  3. In the Data Collection Item Name enter the name under which you'll be able to access individual array items, for example: item. The item object has several built in properties:
    • To access the actual value of the item, use the value property: ${item.value}
    • To get an item's index, use ${item.index}
    • Since arrays number from 0 instead of 1, you can use the convenience property ${item.natural} to get the item's index as if it were counted by a human, that is to say, starting from 1.
    • To identify the first, or the last iteration, use ${item.first} and {item.last}
  4. You can skip iterations of as many items as you wish, starting from the beginning of the array, by entering an offset number in the Offset field
  5. Entering a limit number in the Limit field limits the loop to the specified number of iterations
  6. You can place any number of other elements inside the Loop element

Example of usage:

Suppose you have an array of players, imaginatively called players, and each player has a score. Here is an example showing how you could output each player's score: