Like Hanzo says, your IF statements need an ENDIF. If your entire IF is on a single line like this: IF A THEN B then it ends at the end of that line. But if it's like this, it needs an ENDIF or everything after the IF is inside it: IF A THEN B ENDIF Because of that, in your program, everything after line 130 is actually inside that IF, including the UNTIL, which is why it breaks.