it's been a long while since i programmed but try this
at the start of the program put in a 'count'
at the end of the programme
(IF[#count]<20 GOTO [here])
you'll find it in chapter 10 of the programming manual.