[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
CppSwitch

(C++) switch

Keywords enabling control over program flow, used in combanation with the case and default keywords.

  1. include <iostream>
int main() { const int diceThrow = std::rand()%6; switch(diceThrow) { case 0: std::cout << "You threw 1 and lost!" << std::endl; break; case 5: std::cout << "You threw 6 and won!" << std::endl; break; default: std::cout << "You threw something useless!" << std::endl; break; } }


If you have a class that uses a state-dependent switch-statement, use polymorphism instead [1].

Code links

'switch' links

Reference





last edited (November 18, 2006) by bilderbikkel, Number of views: 2410, Current Rev: 7 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.