1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
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

    -Job-

    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):

    switch(y){
       case Math.Pow(x, 6)/6:
              //do something
       case Math.PI*Math.Pow(x, 2):
              //do something else
    }
     
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Switch Statements
  1. Goto statements (Replies: 25)

Loading...