When you start building your own production processes, you will eventually reach a point where you want to perform certain steps multiple times, in other words, use a loop. As you might have noticed in the first lesson of this unit, the Production Process Designer does not offer a control for this. Therefore, we need to build the loop ourselves, which will show you some more controls in detail. To build a loop in the Production Process Designer, we need three elements: a local variable (1), at least one script task (2), and a condition (3).
1. Local/Process Variable
The local/process variable allows you to store data during the production process runtime. (We will later discuss global variables that allow you to store data independent of the process.) Most of the time, this is the index of the array you are looping over. So, it is advisable to start counting at 0 instead of 1, as the first element of an array has the index 0 in JavaScript.
2. Script Task
You will at least need a simple script task that increases the index variable in each iteration of the loop. In some cases, when you want to build more complex conditions, you might need a script task for the condition as well.
3. Condition
The condition will be used to decide when your loop should terminate or the following code will be executed.
In the screenshot, you already see a simple example, which we will build in the next demonstration to ensure that each element is understood correctly. The example shows a whole loop. If you rearrange the elements, placing the condition at the end of the loop content, you can also create a do-while loop.
Note
As we now come to the more complex modeling aspects, please make sure that you keep production processes fairly simple. To get some sense of the complexity of the processes, you may read the table under Restrictions for Cloud Processes under this note. For example, there is a max loop count of around 200 iterations or a max call stack depth of 10.