Home

END statements of labeled loops should be labeled

Description

    The END statements of labeled loops should be labeled rule states that when a loop is labeled, the corresponding END statement should also be labeled. This is important for readability and maintainability of the code, as it makes it easier to identify which loop a particular END statement belongs to. It also helps to ensure that the loop is properly closed, as any errors in the loop's structure can be easily identified. This rule is applicable to all types of loops, including FOR, WHILE, and REPEAT loops.

Key Benefits

  • Ease of Debugging: END statements of labeled loops should be labeled rule helps in debugging the code more easily.
  • Readability: Labeling the END statements of loops improves the readability of the code.
  • Maintainability: Labeling the END statements of loops makes the code more maintainable.

 

Non-compliant Code Example

BEGIN
	<<ForLoopOnCustomer>>
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT          --Non compliant code (END statements of labeled loops is not labeled)
		LOOP
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			ELSE
				DBMS_OUTPUT.PUT( i || ' IS NULL' );
			END IF;
		END LOOP;
	COMMIT;
END;

Compliant Code Example

BEGIN
	<<ForLoopOnCustomer>>
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT       --Compliant code (END statements of labeled loops is labeled)
		LOOP
			IF CUSTOMER_TABLE(i) IS NOT NULL THEN
				DBMS_OUTPUT.PUT( i || ' = (' || CUSTOMER_TABLE(i).Name || ', ' || CUSTOMER_TABLE(i).PhoneNumber || ')' );
			ELSE
				DBMS_OUTPUT.PUT( i || ' IS NULL' );
			END IF;
		END LOOP ForLoopOnCustomer;
	COMMIT;
END;
Visual Expert 2024
 VEPLSQLRULE80