Can someone describe to me what a "switch" does?
Can someone describe to me what a "switch" does?
Switch isn't a function, it's a keyword.
I'm sure someone here could describe to you what a "switch" does, but we are forced to wonder why you didn't type "C switch" into Google and hit "I'm feeling lucky". (I know some people don't like MSDN help docs, but this one doesn't look too bad.)
switch statement provides multiple way branching. ie it allows users to select any 1 of the several alternatives.
its syntax is:
Code:switch (expression) { case label 1 : block1; break; case label 2 : block2; break; case label 3 : block3; break; . . . . . case labelmax : blockmax; break; default : dblock; break; }
Last edited by ajayd; 02-15-2008 at 01:53 AM.
no case before default
http://www.cppreference.com/keywords/switch.html
All problems in computer science can be solved by another level of indirection,
except for the problem of too many layers of indirection.
– David J. Wheeler