How to create a loop but not For Each loop?

Hi, I'm having trouble with create a normal loop, OutSystems provides a For Each loop but it requires a record list to use but I don't really need it.


My job is create a list with n (n is a dynamic integer) items. I want to create a loop to iterate from 0 to n -1  then I can do a ListInsert(). Please help.

Solution

Hi Long!

You could use an If widget with the condition of a variable used as a counter (for example: Counter <= n-1). One branch contains the loop logic that goes back to the If widget, the other branch continues into the rest of the server/screen action. Set an assign before that If widget so that you can set the Counter to an initial value.

Kind regards,
Joseph Enriquez

Solution

Joseph Enriquez wrote:

Hi Long!

You could use an If widget with the condition of a variable used as a counter (for example: Counter <= n-1). One branch contains the loop logic that goes back to the If widget, the other branch continues into the rest of the server/screen action. Set an assign before that If widget so that you can set the Counter to an initial value.

Kind regards,
Joseph Enriquez

Brilliant, why I can't think of If widget. Thanks for your support.


Hi Long,

As shown on the example below you could use an if widget with a count variable to create a loop.

Use an assign to reset the counter to 0 at every start then check your counter against Input (n) to loop through the inserts until the counter has reached Input (n).

Hope this helps!