The Loop-activity now only loops over a list. If you want to loop over anything else you have to build your loop. For instance like this:
Instead I would like the loop to have a condition.
For instance loop 3 times (and of course in the loop have a counter available):
or with a more complex condition (in this example Date needs to increase every loop):
We can even give the loop a property 'max nr of runs' after which the loop would throw an error, thus preventing uncaught endless looping.
As a solution for the `Do X Times` case that avoids rebuilding the ‘loop with counter’ logic every time that works for me:
In my project I create a separate microflow `CreateXTimesList` with one Integer parameter X. Inside that microflow I build up a list with X items (what type of item doesn’t really matter) and return it. The next time you want to loop X times, you first call the microflow `CreateXTimesList` with the X you want, and after that you iterate over the resulting list. Everything in your loop will then be executed X times.
I guess this approach does not perform optimally, but as long as the X is not that big, it should not matter that much.
(And if you need the counter inside the loop, you can modify ‘CreateXTimesList’ so that it creates a list with objects that contain the loop numbers)
@Nikel Kruizinga I like your suggestion for looping over an Enum. Same goes for looping over a listOfObjects. Also you indeed do want the loop to remain easy to debug and the overhead should be minimal.
I am not a fan. Especially not of the while loop, which is fundamentally complex to reason about. It's much easier to reason about what a loop will do when you can trace all the steps in it, which is the case by default in the way you currently create a loop in Mendix.
If you would have said that we should be able to iterate over all the values of an enum, then yeah, you'd have my vote :).
One year old idea with 50 votes, will this ever get on the Mendix backlog?
This is a great idea! Thank you for the submission
Would be very handy!
Especially the do x times
Only if it is done efficiently without overhead, otherwise I am happy to build by myself with not more overhead.
Something you learn in your first programming lesson. Should definitely be part of Mendix ;-)
Great idea! Sounds like such a basic feature.
great idea!
it would also be awesome if we could loop over an enumeration :)
I really like this idea. It would save us developers a lot of time not having to build custom loops everytime!
Happens so often, that you have to build the shown workaround to achieve "Do-While"-loops.
I don't understand how Mendix could ignore that for so long, which is a basic operation in almost all programming languages.
Sounds good!