Best practice for keeping a while loop in check

Options

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

  • Lefteris - blupry.com
    Lefteris - blupry.com Member ✭✭
    Answer ✓
    Options

    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