(C++) case
February 24, 2017 · View on GitHub
(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"); } }