Go back to Richel Bilderbeek's homepage.
Go back to Richel Bilderbeek's C++ page.
Keyword to state which values to switch on. If there is no named value to switch on, default can be
used optionally.
{
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.