Placing an IF
statement on the same line as the closing END
from a preceding IF
, ELSE
, or
ELSE IF
block can lead to confusion and potential errors. It may indicate a missing ELSE
statement or create ambiguity for
maintainers who might fail to understand that the two statements are unconnected.
The following code snippet is confusing:
IF (condition1) BEGIN
EXEC something
END IF (condition2) BEGIN -- Noncompliant
EXEC something
END
Either the two conditions are unrelated and they should be visually separated:
IF (condition1) BEGIN
EXEC something
END
IF (condition2) BEGIN
EXEC something
END
Or they were supposed to be exclusive and you should use ELSE IF
instead:
IF (condition1) BEGIN
EXEC something
END ELSE IF (condition2) BEGIN
EXEC something
END