include::../description.adoc[]

== Noncompliant Code Example

----
switch ($myVariable) {
  case 1:  
    foo();
    break;
  case 2:  // Both 'doSomething()' and 'doSomethingElse()' will be executed. Is it on purpose ?
    do_something();
  default:  
    do_something_else();
   break;
}
----

== Compliant Solution

----
switch ($myVariable) {
  case 1:  
    foo();
    break;
  case 2:  
    do_something();
    break;
  default:  
    do_something_else();
   break;
}
----

== Exceptions

This rule is relaxed in following cases:


----
switch ($myVariable) {
  case 0:                  // Empty case used to specify the same behavior for a group of cases.
  case 1:  
    do_something();
    break;
  case 2:                  // Use of continue statement
    continue;
  case 3:                  // Case includes a jump statement (exit, return, break &etc)
    exit(0);
  case 4:
    echo 'Second case, which falls through';
    // no break        <- comment is used when fall-through is intentional in a non-empty case body
  default:                 // For the last case, use of break statement is optional 
    doSomethingElse();
}
----

include::../see.adoc[]

ifdef::env-github,rspecator-view[]
'''
== Comments And Links
(visible only on this page)

include::../comments-and-links.adoc[]
endif::env-github,rspecator-view[]
