There's and extra 'END' in the code. The last matches to the 'BEGIN' and the second to last matches to 'LOOP', leaving the 'END LOOP' hanging out there.