Home

GOTO should not be used to jump backwards

Rule description

  • GOTO should not be used to jump backwards

 

Non-compliant Code Example

DECLARE
  result PLS_INTEGER := 0;
  cnt PLS_INTEGER := 1;
BEGIN
   <<get_result>>
  result := result + cnt;
  cnt := cnt + 1;

  IF cnt <= 5 THEN
    GOTO get_result;  --Non compliant code
  END IF;

  DBMS_OUTPUT.PUT_LINE('Sum from 1 to 5 is ' || result); 
END;

Compliant Code Example

DECLARE
  result PLS_INTEGER := 0;
BEGIN
  FOR cnt IN 1 .. 5 LOOP --Compliant code
    result := result + cnt;
  END LOOP;

  DBMS_OUTPUT.PUT_LINE('Sum from 1 to 5 is ' || result);  
END;
Visual Expert 2020
 VEPLSQLRULE20