Jump to content

  • Log In with Google      Sign In   
  • Create Account


#Actualalnite

Posted 11 November 2012 - 12:30 PM

While this might be language-dependent, you can't normally switch-case objects like strings. switch-case could only be used on integers, as it creates a jump/branch table. Additonally, in some languages, you are allowed to fall through a case statement.
switch (x) {
	 case 0:
	 	 doSomething();
	 case 1:
	 	 doSomethingElse();
	 	 break;
	 default:
	 	 doDefault();
	 	 break;
}

if x = 0, doSomething() and doSomethingElse() are executed. This style of coding could be useful in certain cases (no pun intended).

#1alnite

Posted 11 November 2012 - 12:30 PM

While this might be language-dependent, you can't normally switch-case objects like strings. switch-case could only be used on integers, as it creates a jump/branch table. Additonally, in some languages, you are allowed to fall through a case statement.
switch (x) {
	 case 0:
	 	 doSomething();
	 case 1:
	 	 doSomethingElse();
	 	 break;
	 default:
	 	 doDefault();
	 	 break;
}

if x = 0, doSomething() and doSomethingElse() are executed. This style of coding could be useful in certain cases (no pun intended).

PARTNERS