PricingBlog

How can I use for loops in Toodle?

  • gerson_ca-1277440122035376260

    Gerson CA

    1 year ago

    Hi I’m learning toddle by recreating some projects from my Intro to Python class.
    Here in trying to convert an input from camelCase to snake_case.
    First, I created a formula to check if it’s upper case or not. However, I’m not sure how can I implement the for loop formula.
    1277440122668847154-Screen_Shot_2024-08-25_at_20.14.29.png
    1277440123042009199-Screen_Shot_2024-08-25_at_20.12.16.png
  • lucasg-1277468762957807680

    Lucas G

    1 year ago

    One way I've done them is with workflows
  • A workflow can call itself
  • So you can track its iterations and effectively make a very flexible for loop
  • lucasg-1277469487456850042

    Lucas G

    1 year ago

    The workflow doesn't have to call itself though you can just call it for every item on its own
  • lucasg-1277469787836125235

    Lucas G

    1 year ago

    Somethign else you can do is also just simply put the input through a lowercase node
  • But you'd have to figure out the underscore
  • gerson_ca-1277790303381753928

    Gerson CA

    1 year ago

    Thank you using the workflow works, although I still wonder why Toddle didn’t add the loop formula. Here’s how I did it
    1277790303360647341-Screenshot_2024-08-26_at_19.38.40.png
  • lucasg-1277799836464316468

    Lucas G

    1 year ago

    I think because loops sometimes get mixed opinions in the dev world
  • But don’t know. Would be a question for @Andreas Møller
  • andreasmoller-1277854674724192287

    Andreas Møller

    1 year ago

    Formulas can also call themselves just like workflows
  • andreasmoller-1277855309917847572

    Andreas Møller

    1 year ago

    We didn’t add loops, because we didn’t need them, between Map,Filter and Reduce you can do almost anything a loop can do
  • The rest of the cases can be solved with recursion
  • You scenario can also be solved with a Map followed by Flatten
  • gerson_ca-1277876164190277635

    Gerson CA

    1 year ago

    Yes!!! I just read about map, filter and reduce. @Andreas Møller was right, I can just use map for this scenario. That’s amazing I learned about this by using Toddle. Thanks for the all the answers, I’m really excited for all of this. 🙌
    1277876163972436043-Screenshot_2024-08-27_at_01.13.07.png
    🙌1