Best practice for keeping a while loop in check
What is the best practice for keeping a while loop in check while building and testing? Currently I create a variable that increments on each run and make it part of the condition for whether the loop continues. So like 'iteration < 100'.
Is this the right way? Is there a simpler way to manage this?
Best Answer
-
Hey @Eli Beachy,
I don't think there is any better way to do so without making it extremely more complex.
A generally good practice I use though, is to update the counter on the first line of the loop, just to make sure an error doesn't block the execution of the variable update. (If you need the correct iteration value of the variable somewhere else, you can always use the current value - 1, if you end up implementing my suggestion).
Answers
-
Thanks @Lefteris - buynocodeapps.com. I figured that was the case but never hurts to ask :) And thanks for the tip.
-
Just to add to this, this is the simplest way I've also used.
You can also play around with using aconditional
and abreak loop
if you want to be able to move this around your function stack (so you can see what's happening in your debugger, etc).
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback