Home

Jump statements should not be redundant

Rule description

  • Jump statements should not be redundant

 

Non-compliant Code Example

WHILE ( SELECT AVG(ListPrice) FROM dbo.DimProduct) < $300  
BEGIN  
    UPDATE dbo.DimProduct  
        SET ListPrice = ListPrice * 2;  
    Continue;     --Non compliant code (Redundant jump statement in while loop)
    SELECT MAX ( ListPrice) FROM dbo.DimProduct  
END 

Compliant Code Example

WHILE ( SELECT AVG(ListPrice) FROM dbo.DimProduct) < $300  
BEGIN  
    UPDATE dbo.DimProduct  
        SET ListPrice = ListPrice * 2;  
    SELECT MAX ( ListPrice) FROM dbo.DimProduct  
    IF ( SELECT MAX (ListPrice) FROM dbo.DimProduct) > $500   --Compliant code (Loop break only when particular condition achieved.)
        BREAK;  
END 
Visual Expert 2020
 VETSQLRULE49