Home
FOR loop end conditions should not be hard - coded
Rule description
- FOR loop end conditions should not be hard - coded
Non-compliant Code Example
BEGIN
<<ForLoopOnCustomer>>
FOR i IN 1 .. CUSTOMER_TABLE.COUNT --Non compliant code (For loop end conditions are hard-coded)
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;
Compliant Code Example
BEGIN
<<ForLoopOnCustomer>>
FOR i IN CUSTOMER_TABLE.FIRST .. CUSTOMER_TABLE.LAST --Compliant code
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;