Here’s an implementation of a while loop that runs as long as the value in the table is not equal to 0. It can be easily modified for any boolean condition by changing the formula in While condition.
The hack used here: a button cannot push itself, but it can push another button, which will then push the first button.
Btw, in case you didn’t find it, a commonly used tricky for a FOR() loop is to use the Sequence() formula and FormulaMap() - e.g. FormulaMap(Sequence(1, 10), CurrentValue+1) or FormulaMap(Contacts, Gmail::SendEmail(... CurrentValue ...))
Why?
This actually proved to be very useful. E.g., if you need to make two or more nested loops (e.g. you have two lists and need to make MxN rows for a cross-join), the only way to do it for now is via my WHILE implementation and a backing table to store current indices. That’s because we cannot access outer CurrentValue. I’ll make a demo on this when I get back from vacation.
UPD: it’s also possible to do it in one Sequence().FormulaMap() loop if we know M and N in advance. But even then it gets very impractical if you have 3 and more lists.
Example scenario I’m talking about: you have students, you have courses, and each course has variable number of lessons. You need to make rows where you link each student to each lesson directly.
@Paul_Danyliuk I wholeheartedly commend the solution and creativity.
I suspect the laugh is mostly for the fact that this is required to handle these types of things - the fact that there is a legitimate need indicates it should be something that exists as a top-level function.
I myself used RegexExtract to get outer CurrentValue access so I could do GroupBy(). (I.e.: Map the indices to a: “X1-Y1,…,Xn-Yn” pattern, then used ((\d+)-[^,]+,*(\2-[^,]+,)*), "gm" to group and extract separate lists.)
And… I was absolutely frustrated by the mental exercise required to get the functionality I need as I needed to get things done, not have to reinvent the concept of GroupBy. I don’t want to have to jump through these hoops to do these things, nor have to implement what is essentially a manual-memory-using-multiple-tables turing machine.
And that is not even to mention the fact that you really don’t want to have this in a production document other people will touch.