title: Why does C++ require breaks in switch statements?
body: <p>When writing <em>switch</em> statements in C++, it seems necessary to include a <em>break</em> after every <em>case</em>. Otherwise, the code will continue to run into the next case.</p>
  
  <p>For example:</p>
  
  <pre><code>int x = 1;
  switch (x)
  {
      case 0:
          std::cout &lt;&lt; "x is 0." &lt;&lt; std::endl;
      case 1:
          std::cout &lt;&lt; "x is 1." &lt;&lt; std::endl;
      case 2:
          std::cout &lt;&lt; "x is 2." &lt;&lt; std::endl;
      default:
          std::cout &lt;&lt; "x is neither 0, 1 nor 2." &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>Will return:</p>
  
  <pre><code>&gt;&gt; x is 1.
  &gt;&gt; x is 2.
  </code></pre>
  
  <p>However:</p>
  
  <pre><code>int x = 1;
  switch (x)
  {
      case 0:
          std::cout &lt;&lt; "x is 0." &lt;&lt; std::endl;
          break;
      case 1:
          std::cout &lt;&lt; "x is 1." &lt;&lt; std::endl;
          break;
      case 2:
          std::cout &lt;&lt; "x is 2." &lt;&lt; std::endl;
          break;
      default:
          std::cout &lt;&lt; "x is neither 0, 1 nor 2." &lt;&lt; std::endl;
          break;
  }
  </code></pre>
  
  <p>Will return:</p>
  
  <pre><code>&gt;&gt; x is 1.
  </code></pre>
  
  <p>My question is: If it is necessary to include the <em>break</em> for every <em>case</em>, then why does C++ require it to be explicitly written at all? Why not just <em>break</em> the <em>switch</em> statement after every <em>case</em> by default in C++? Are there any examples when this behaviour may not in fact be desired?</p>