Is it possible for you to use a WHILE loop instead of the IF/ENDIF?
It can perform much the same function except you can modify the controlling variables upon which the WHILE test is performed, within the WHILE loop, or within a GOSUB/RETURN, and then it will exit gracefully.