The following example sets up an infinite loop but defines an ON ESCAPE routine to exit it.
SET ESCAPE ON
ON ESCAPE DO stopit
WAIT WINDOW 'Press ESC to stop loop' NOWAIT
glMoreLoop = .T.
DO WHILE glMoreLoop
ENDDO
RETURN
PROCEDURE stopit
glMoreLoop = .F.
RETURN