== Why is this an issue?

When a single primitive is tested against three or more values in an ``++if++``/``++else if++`` structure, it should be converted to a switch instead for greater readability.


=== Noncompliant code example

[source,cpp]
----
public void doSomething(int i) {
  if (i == 0) {
    // ...
  }
  else if (i == 1) {
    // ...
  }
  else if (i == 2) {
    // ...
  }
  else if (i == 3) {
    // ...
  }
  else {
    // ...
  }

----


=== Compliant solution

[source,cpp]
----
public void doSomething(int i) {
  switch(i) {
    case 0:
      // ...
      break;
    case 1:
      // ...
      break;
    case 2:
      // ...
      break;
    case 3:
      // ...
      break;
    default:
      // ...
      break;
  }
----


== Resources

* {cpp} Core Guidelines - https://github.com/isocpp/CppCoreGuidelines/blob/e49158a/CppCoreGuidelines.md#es70-prefer-a-switch-statement-to-an-if-statement-when-there-is-a-choice[ES.70: Prefer a `switch`-statement to an `if`-statement when there is a choice]

ifdef::env-github,rspecator-view[]

'''
== Implementation Specification
(visible only on this page)

=== Message

Convert this "if/else if" structure into a "switch".


'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]

endif::env-github,rspecator-view[]
