ACR Rules

  1. Home
  2. Docs
  3. ACR Rules
  4. Reliability (40)
  5. Chain of “if/else if” statements should have different conditions

Chain of “if/else if” statements should have different conditions

Introduced in version: 1.3 (29 Jan 2020)

A chain of if/else if statements is evaluated from top to bottom. At most, only one branch will be executed: the first one with a condition that evaluates to true.

Therefore, duplicating a condition automatically leads to dead code. Usually, this is due to a copy/paste error. At best, it’s simply dead code and at worst, it’s a bug that will likely lead to unexpected behavior.

Noncompliant example:

if $EntityWithLongName/VariableWithLongName = Moduleee.Enumeration.ValueAAWithLongName then 1
else if $EntityWithLongName/VariableWithLongName = Moduleee.Enumeration.ValueAAWithLongName then 2
else 3

Compliant example:

if $EntityWithLongName/VariableWithLongName = Moduleee.Enumeration.ValueAAWithLongName then 1
else if $EntityWithLongName/VariableWithLongName = Moduleee.Enumeration.ValueBBWithLongName then 2
else 3