switch statement - Can someone explain switching in Objective C -
i started learning objective c , don't understand switches. can please explain them me?
thanks
a switch statement meant used in place of if else statements
for example
int =4; if(a == 1) dosomething(); else if(a == 2) dosomethingelse(); else if(a == 3) blah(); else caseunaccountedfor();
is equivalent to
int =4; switch(a) { case 1: dosomething(); break; case 2: dosomethingelse(); break; case 3: blah(); break; default: caseunaccountedfor(); break; }
if 1 of cases match, switch statement not automatically exited why there's break statement @ end of each case. case 'default' matches every other case besides ones explicitly list.
Comments
Post a Comment