Home

IF statements should not be nested too deeply

Rule description

  • IF statements should not be nested too deeply

 

Non-compliant Code Example

BEGIN
 IF score > 35 THEN 
     IF score > 40 THEN 
		IF score > 50 THEN 
			IF score > 60 THEN      --Non compliant code (IF statements nested deeply beyond default defined 4 level)
				IF score > 70 THEN  --Non compliant code (IF statements nested deeply beyond default defined 4 level)
					DBMS_OUTPUT.PUT('Grade A');
				END IF;
			END IF;
			DBMS_OUTPUT.PUT('Grade B');
		END IF;
	END IF;
	DBMS_OUTPUT.PUT('Grade C');
 END IF;
END;

Compliant Code Example

BEGIN
 IF score > 35 AND score < 50  THEN 
		IF score > 50 AND score < 70 THEN 
				IF score > 70 THEN 
					DBMS_OUTPUT.PUT('Grade A');
				END IF;
			DBMS_OUTPUT.PUT('Grade B');
		END IF;
	DBMS_OUTPUT.PUT('Grade C');
 END IF;
END;
Visual Expert 2020
 VEPLSQLRULE44