# G-4375: Always use EXIT WHEN instead of an IF statement to exit from a loop.

Minor

Maintainability

## Reason

If you need to use an EXIT statement use its full semantic to make the code easier to understand and maintain. There is simply no need for an additional IF statement.

DECLARE
co_first_year CONSTANT PLS_INTEGER := 1900;
BEGIN
<<process_employees>>
LOOP
my_package.some_processing();

IF EXTRACT(year FROM SYSDATE) > co_first_year THEN
EXIT process_employees;
END IF;

my_package.some_further_processing();
END LOOP process_employees;
END;
/


## Example (good)

DECLARE
co_first_year CONSTANT PLS_INTEGER := 1900;
BEGIN
<<process_employees>>
LOOP
my_package.some_processing();

EXIT process_employees WHEN EXTRACT(YEAR FROM SYSDATE) > co_first_year;

my_package.some_further_processing();
END LOOP process_employees;
END;
/