WHILE loop implementation

Coda is now officially Turing-complete :grin:

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.


Dear @Paul_Danyliuk,

Thank you sharing your creative approach and thereby supporting the “out of the box thinking” :fountain:


1 Like

Ha nice!

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 ...))

I did, and I posted a link in that thread to here.

The problem with Sequence/FormulaMap approach is that it only works for specified number of iteration, whereas while loops can have dynamic condition.

Hold on, I’m about to post another doc show-and-tell right now.

1 Like

Very cool!

I suppose you could separate the check from the action button for clarity.

Also where’s the panic button? I just broke Coda, it’s counting to -Inf ! :stuck_out_tongue:

Thanks. Updated the example.

No panic button in this demo :slight_smile: but you can manually set the counter value to above zero to terminate the loop eventually.

Here’s what I did with this newly acquired knowledge, lol: