To improve the code readability always use EXIT WHEN instead of an IF statement to exit from a loop.
if condition1 then exit; end if;
exit when condition1;