Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) switch

 

switch is a keyword to perform a kind of multiple if statements on a certain value. case determines which values can be switch on. If there is no named value to switch on, default can be used optionally.

 

 

 

 

 

Example

 

 

 

 

 

 

Advice

 

 

 

 

 

References

 

  1. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 9.8. Advice, page 240: '[2] Prefer a switch-statement to an if-statement when there is a choice'
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 22.7. Advice. page 663: '[10] Prefer virtual functions to repeated switch-statements based on typeid or dynamic_cast'

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict