Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) case

 

case is a keyword to state which values to switch on. If there is no named value to switch on, default can be used optionally.

 

#include <cassert>
#include <iostream>

int main()
{
  const int coin = std::rand() % 2;
  switch (coin)
  {
    case 0: std::cout << "Heads" << std::endl; break;
    case 1: std::cout << "Tail" << std::endl; break;
    default: assert(!"Should not get here");
  }
}

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml