For Loop Over a Range

The current For Each activity is used to loop over a collection of items. This is definitely useful, but the standard for loop in uses a counter and a range and iterates over an integer value. See this documentation:

I am requesting that a new activity be added that can take a counter variable, start and end numbers, as well as a step amount.

This would be very helpful for creating an idiomatic means of performing a given bit of code multiple times. The current workarounds are clunky, such as using a while loop with an assign activity to assign a variable being used as the index to itself with the step or attempting to create collections variables with the number of elements to represent the total amount of times that one wishes to iterate.

You can use a For Each activity with i as the loop variable and Enumerable.Range(1,20) to loop from i=1 through i = 20. This isn’t capable of stepping more than one but it does iterate over an integer value fairly easily.


Hello Daniel,

I wasn’t aware of that, thank you. That mostly fixes the issue I was having. I was getting frustrated trying to create a collection that had initialized with a certain number of indexes and it wasn’t working.

I think what I initially suggested would still have value, not only for the skip but to have it be more idiomatically shown using the Workflow foundation setup. However, you’re right, for the most part, what you’re suggesting works.

1 Like

@dmccammond @DanielMitchell which TypeArgument need to be set within Properties in order to get dedicated result from your example? Thanks in advance

It’s Integer, so Int32.

You could also figure it out by mousing over the method as it will tell you what the output variable types would be.