Home

END LOOP should be followed by a semicolon

Description

    The END LOOP should be followed by a semicolon (;) rule in PL/SQL code states that the END LOOP statement must be followed by a semicolon (;) in order for the code to be valid and executable. This is because the END LOOP statement marks the end of a loop, and the semicolon (;) is used to terminate the statement. Without the semicolon (;), the code will not be valid and will not execute correctly.

Key Benefits

  • Ensures Syntactic Accuracy: END LOOP should be followed by a semicolon to ensure that the loop is correctly terminated;
  • Reduces Programming Errors: The semicolon after END LOOP helps reduce programming errors by making it explicit that the loop has ended;
  • Makes Code Easier to Read: Including the semicolon after END LOOP makes code easier to read, as the reader can easily identify the end of the loop.

 

Non-compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
	   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            --Non compliant code (Loop ends without semicolon)
	COMMIT;
END;

Compliant Code Example

BEGIN
	FOR i IN 1 .. CUSTOMER_TABLE.COUNT
	   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;       --Compliant code (Loop ends with semicolon)
	COMMIT;
END;
Visual Expert 2024
 VEPLSQLRULE9