One method is to have an if statement witin the for loop that checks on every iteration of the loop if a condition is satisfied. If it is, the loop continues, if not you can set the for loop variable to be your endpoint during the else statement.