Home

Conditionally executed code should be denoted by either indentation or BEGIN...END block

Description

    The rule "Conditionally executed code should be denoted by either indentation or BEGIN...END block" is used to ensure that code is properly organized and easily readable. This rule states that any code that is conditionally executed should be denoted either by indentation or by using a BEGIN...END block. Indentation helps make code easier to read and understand, while BEGIN...END blocks clearly denote the start and end of a conditionally executed block of code. This rule helps ensure that code is properly structured and organized, making it easier to maintain and debug.

Key Benefits

  • Easier to read: Conditionally executed code should be denoted by either indentation or BEGIN...END block, making it easier to read and understand.
  • More organized: This rule allows code to be more organized and structured, making it easier to maintain and debug.
  • More reliable: By using either indentation or BEGIN...END block for conditionally executed code, the code is more reliable and less likely to produce errors.

 

Non-compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100   --Non compliant code (IF and ELSE IF statements are not denoted by either indentation or BEGIN...END block)
    PRINT 'The number is large.';  
ELSE IF @Number < 10  
    PRINT 'The number is small.';  
ELSE  
    PRINT 'The number is medium.';  
GO

Compliant Code Example

DECLARE @Number int;  
SET @Number = 50;  
IF @Number > 100   --Compliant code (IF and ELSE IF statements are denoted by either indentation or BEGIN...END block)
    PRINT 'The number is large.';  
ELSE   
    BEGIN  
        IF @Number < 10  
            PRINT 'The number is small.';  
        ELSE  
            PRINT 'The number is medium.';  
    END ;  
GO  
Visual Expert 2024
 VETSQLRULE9