Can someone describe to me what a "switch" does?
This is a discussion on What is the "switch" function? within the C Programming forums, part of the General Programming Boards category; 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 12:53 AM.
no case before default
http://www.cppreference.com/keywords/switch.html
If I have eight hours for cutting wood, I spend six sharpening my axe.