Why is this an issue?
BEGIN...END
can be omitted from a one-line block, such as with an IF
statement or WHILE
loop, but doing so
can be misleading and induce bugs.
This rule raises an issue when the indentation of the lines after a one-line block indicates an intent to include those lines in the block, but the
omission of BEGIN...END
means the lines will be unconditionally executed once.
Note that this rule considers tab characters to be equivalent to 1 space. If you mix spaces and tabs you will sometimes see issues in code which
looks fine in your editor but is confusing when you change the size of tabs.
Noncompliant code example
IF (0=1)
EXEC firstActionInBlock;
EXEC secondAction; -- Noncompliant; executed unconditionally
EXEC thirdAction;
IF (0=1) EXEC firstActionInBlock; EXEC secondAction; -- Noncompliant; secondAction executed unconditionally
IF (0=1) EXEC firstActionInBlock; -- Noncompliant
EXEC secondAction; -- Executed unconditionally
Compliant solution
IF (0=1) BEGIN
EXEC firstActionInBlock;
EXEC secondAction;
END
EXEC thirdAction;
Resources