Skip to content

Gloop While Icon

While

The While Step in Gloop is very similar to the while statement in Java and other programming languages (but with extra features). Like in Java, when the execution of its children/block has completed, the While Step will run them all again, as long as its condition is met.

While Steps in Gloop rely on a combination of the Expression and While On Error properties to determine whether to run again or not. When the While Step needs to determine whether it's going to run again, it will evaluate the Expression property (as a Groovy snippet if Evaluate is true), or use the literal value of the Expression property and do the following:

  • If the result of the expression is a Number (primitive or not) or a String with a numeric value, it will check if the number is less than or equal to the number of times the While Step has executed. If it is, it will run again. This means that you can write an Expression of 10 and the While Step will run 10 times.

  • If the result of the expression is a boolean or Boolean, it will use its value to determine whether to run again.

  • If the result of the expression is a String which isn't numeric, it will check if the value of the String is true (case insensitive).

  • Any other types of results from the Expression will result in an exception being thrown.

The While Step will introduce two variables to Gloop while it's being executed:

  • $gloopIndex - a zero-based counter, which increments at the end of the run
  • $gloopCount - a one-based counter, which also increments at the end of the run

While text

If your While Step only has a plain number as the Expression, its text in the Gloop Editor will appear as While $gloopIndex < <expressionValue>; this makes your Gloop code much easier to read. Otherwise, it will appear as While <expressionValue>, as shown below:

Gloop While Labels

While There's an Error

While Steps have a unique property called While On Error. If this is set to true, the While Step will run again only if the Expression condition is met and an exception was thrown whilst invoking its child steps. This is useful for retrying an operation that sometimes may not work; for example, trying to connect to remote servers or URLs. When this is true, exceptions are ignored and the While Step will start over. If While On Error is false and an exception is thrown, the While Step will not catch it and the Gloop Engine will throw it back to TORO Integrate. For instances like this, you can catch the error with a parent Block Step with a catch or a parent While Step whose While On Error is true instead.

Adding Elements to an Array

While Steps also have an Output Array property (same as the Iterate Step). This makes it easy to map or transform data under the While Step and have it added to an array or cursor.

The array that the step is adding to will appear as a single item in the Mapper view when you're in the context of the While Step. Look closely at the Mapper view below to see how the While Step changes what's available in the mapper. You will notice that the $gloopIndex and $gloopCount variables being added, and the output array (which in this example is called myArray) changes from an array to a single item (the array brackets badge on the bottom-right doesn't appear anymore) when the Mapper is underneath the While Step.

Coder Studio Gloop Iterate Context Changes

Other Features

While Steps can also be configured to delay at the end of an iteration (this is useful in combination with the While On Error property when retrying things) and can close your Gloop Cursors after finishing if you choose to do so (by setting Close Output Cursor to true).