Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Switch Statements

  1. May 2, 2007 #1
    I'm new to programming and learning the switch statements right now. I'm wondering if you can add/subtract/multiply/divide equations in the switch statements.

    Example: y = x^6/6

    And if I want that in case 1, how do I calculate y assuming I already have x input beforehand?
  2. jcsd
  3. May 2, 2007 #2


    User Avatar
    Science Advisor

    In Java cases in a switch statement need to be constant primitive types or enumerated types. C# relaxes this a little adding support for strings. But you can't have the following:
    Code (Text):

       case Math.Pow(x, 6)/6:
              //do something
       case Math.PI*Math.Pow(x, 2):
              //do something else
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook