You may want to explore the WHILE-WEND command.