I'm going to assume you're using a For loop... If this is the case you can do two things. One, you could switch to a while loop, and just have the conditions 'if i = [former input to For loop N], stop', as well as the early exit condition wired to the stop (ORed).
The other is that you could have all of your code inside error cases (case structure with error wired to the case selector), and once your early exit condition occurs, set the error to true, and the For loop will finish itself without executing any more code (essentially instant).
I would recommend the while loop method, as there's less wasted CPU cycles. I could however be way off with this answer. If so, please be a bit more specific.
Hope this helps