Go back to Richel Bilderbeek's homepage.

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

 

 

 

(C++) case

 

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

 

 

#include <iostream>

#include <cassert>

 

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.