Code inspection: Duplicated sequential 'if' branches
This inspection detects consecutive if
statements with identical bodies. Such redundancy negatively impacts code readability and maintainability. It indicates that the logic can potentially be simplified by consolidating conditions where applicable.
Consider the example below, where two sequential if
statements share the same body. JetBrains Rider suggests combining their conditions into one statement to reduce repetition.
public string ValidateInput(int input)
{
if (input == 10 || input == 20)
return Validate(input);
if (input == 30 || input == 40)
return Validate(input);
return "invalid input";
}
string Validate(int i) => "valid input";
public string ValidateInput(int input)
{
if (input == 10 || input == 20 || input == 30 || input == 40)
return Validate(input);
return "invalid input";
}
string Validate(int i) => "valid input";
Last modified: 24 March 2025