It looks like your premise is that you have a default number of times the loop should execute but an occasional condition where it's different. It might be better to use a while loop instead, but regardless you can just do:
if i == some_calculated_threshold:
break
to drop out of the loop instead.