# Generating a sequence of numbers in @Formula

I wanted to create a list with numbers in sequence, like 1 : 2 : 3 : 4 : 5, and didn´t think it was possible to to this dynamically. Since R5 cannot loop inside @Formulas, I had to think out another way.

Since the language is quite powerful regarding the list operator, you could do it this way:

``min:=2; max:=10; startDate:=[01/01/01]; ((@TextToTime(@Explode(@TextToTime(@Text(startDate) + "-" + @Text(@Adjust(startDate; 0; 0; max - min; 0; 0; 0))))) - startDate)/86400) + min;``

The start date is irrelevant, since we are just counting days. The @Explode(daterange) function is very special, since it creates a list with all dates in the specified range. And since the list operator has higher precedence than the subtraction operator, the subtraction of the start date is made on the whole list! When subtracting / adding two dates, you get the result as the difference in seconds, so we have to divide it with 60*60*24=86400. Simple, isn´t it? 🙂

To get a list of numbers that are more than one step apart, do like this:

``min:=12; max:=36; step:=3; steps:=@If(step=0; 0; (max - min) / step); startDate:=[01/01/01]; allOptions:=(@TextToTime(@Explode(@TextToTime(@Text(startDate) + "-" + @Text(@Adjust(startDate; 0; 0; max-min; 0; 0; 0))))) - startDate) / 86400; options:= @If( (steps != 0) & (allOptions != 0) & (step != 0); (step * @Subset(allOptions; steps + 1)) + min; 0 ); options``