Loop object


Loop objects contain a counter variable that is incremented each time the object executes. The loop object also can stop execution if a given count has been reached. On initialization and after a reset call the internal counter starts at zero.

After inserting a loop object use the property dialog to specify a maximum count number. If the property "Block when finished" is set to "Yes" the current thread is stopped when control reaches the loop object and the internal count has reached the value specified with the "Count" property. The output variable "current count" has the value of the internal counter, the output variable "Again" is 1 if the internal counter has not reached the "Count" property and 0 if it has reached the specified count. This variable can be used in connection with the Yes/No objects.

The loop object also has a "Reset" action which can be called to restart the internal counter.
Fig. 1: Object layout for loop object
Figure 1 shows two object layouts for the loop object. On the left side the "Block when finished" is used for loop termination. On the right side the "Yes" object is used. If "Block when finished" is set to "no" and no yes object is used, the internal counter is incremented infinitely and can be used just as a normal counter.

A loop normally is not reentrant because of the loop object's internal counter variable. If a single loop should be used by multiple threads at the same time, connect the "CurrentCount" output of the loop object to the "Loop Count" input property at the end of the loop. So each thread always sets the internal counter variable to the value belonging to the thread that is currently executing the loop object and a single loop can be executed by multiple threads at the same time.

The Vimms User Manual