DF111: Code contains too many nested IF, WHILE, or TRY statements (Nesting level > 4).

Last modified: September 6, 2024

The topic describes the DF111 T-SQL code analysis rule.

Category

STYLE

Message

Code contains too many nested IF, WHILE, or TRY statements (Nesting level > 4).

Description

For better readability and performance, it’s recommended to avoid excessive nesting of control flow statements such as IF, WHILE, and TRY.

Additional information

Excessive nesting of control flow statements such as IF, WHILE, or TRY can make the code harder to read, understand, and maintain. It increases complexity and reduces readability, as developers need to mentally track multiple levels of nested logic. Moreover, deeply nested code can be error-prone and difficult to debug.

Noncompliant code example


Compliant solution