← back to index

S1066 — Mergeable "if" statements should be combined

Language: VB.NET  |  Type: CODE_SMELL  |  Severity: Major

Tags: clumsy

Why is this an issue?

Nested code - blocks of code inside blocks of code - is eventually necessary, but increases complexity. This is why keeping the code as flat as possible, by avoiding unnecessary nesting, is considered a good practice.

Merging if statements when possible will decrease the nesting of the code and improve its readability.

Code like

If condition1 Then
    If condition2 Then ' Noncompliant
        ' ...
    End If
End If

Will be more readable as

If condition1 AndAlso condition2 Then
    ' ...
End If