How do I force a loop to check its condition after every line of execution instead of only when the entire block finishes?
I have a while(!statement) { } loop, but statement can be changed by several different methods and should force the loop to break immediately after the current line in the loop has finished executing; instead of when the entire loop block has completed a cycle.
Is there any way to do this?
Depending on what you are doing, you could consider having each statement be a delegate, create an array of delegates, and run a for loop across the array. That way the loop is just two lines: one that checks the condition, and when that executes the delegate at the current array position.
yes, but you won't like it... just put a if (!condition) break;
after each instruction ;)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With