Jump to content

  • Log In with Google      Sign In   
  • Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

#ActualServant of the Lord

Posted 16 July 2012 - 02:52 PM

Some languages allow this:

switch(name){
  case "Tiffany":
  case "tiffany":
  case "Tiffany McClure":
	...
  break;
  default:
	...
}
Close enough?

C++ switch statements only work with some data types (mostly ints) - not with std::strings. Even so, that's pretty ugly syntax. Posted Image

#1Servant of the Lord

Posted 16 July 2012 - 02:51 PM



if (username == "Tiffany" || "tiffany" || "Tiffany McClure" || "tiffany McClure" || "Tiffany Mcclure" || "tiffany mcclue")



Am I the only one thinking that looks pretty elegant? Is there any language that implements this way of checking the same variable for different boolean cases?

It looks to me like "Tiffany" is the real string to look for here, so I would convert to lowercase and check for "tiffany".. what if she wrotes "Tiffany Cupcake" ? Posted Image You'll miss that.

Some languages allow this:
switch(name){
  case "Tiffany":
  case "tiffany":
  case "Tiffany McClure":
	...
  break;
  default:
	...
}
Close enough?

C++ switch statements only work with some data types (mostly ints) - not with std::strings. Even so, that's pretty ugly syntax. Posted Image

PARTNERS