Home

In labeled loops EXIT should exit the label

Rule description

  • In labeled loops EXIT should exit the label

 

Non-compliant Code Example

DECLARE errorLog_ EXCEPTION; 
BEGIN
	<<CUSTOMER_TABLE_ITERATION>>            --Non compliant code (EXIT is not labeled as loop label)
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT  
		LOOP
            IF CUSTOMER_TABLE(i).Id > 25 THEN 
				EXIT;
			ELSIF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;

Compliant Code Example

DECLARE errorLog_ EXCEPTION; 
BEGIN
	<<CUSTOMER_TABLE_ITERATION>>            --Compliant code (EXIT is labeled as loop label)
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
		LOOP
            IF CUSTOMER_TABLE(i).Id > 25 THEN 
				EXIT CUSTOMER_TABLE_ITERATION;
			ELSIF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			END IF;
		END LOOP;
EXCEPTION
  WHEN ERRORS THEN
	RETURN;
END CUSTOMER_TABLE_ITERATION;
Visual Expert 2020
 VEPLSQLRULE81