#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2010
    Posts
    1
    Rep Power
    0

    Smile Hello everyone! + tiny question with case statement


    Hi everyone,
    I join this community in the spirit that hopefully I can help (at least where I can) and learn. I feel a bit like a noob not knowing the actual formalities when joining a forum such as this but basically I started learning ruby this semester and I have found it strangely addictive.

    Oh, with the tiny question...

    I have a script that is basically as such:
    #used to readjust dates when months are days are added to it

    def function(x,y,z)
    valid = false
    until var == true
    case z
    when 1
    #do something
    when 2
    #do something
    else
    var = true
    end
    end

    The point I am really trying to get across is:
    when the 'when' is satisfied, does it go to the next 'when' then 'else'

    If it is appropriate I can post the code... it isn't excessive in length.
    Any thoughts or input would be appreciated.

    [edit] Apologies all, just my logic playing tricks on me
    Last edited by andrewbriscoe87; September 30th, 2010 at 07:45 PM. Reason: solved the tiny question
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2005
    Location
    los angeles
    Posts
    5
    Rep Power
    0
    This should clear things up:

    PHP Code:
    "cat"

    case x
    when 
    "cat"
      "meow"
    when "dog"
      "woof"
    else
      
    "unknown animal"
    end

    # or

    case
    when x == "cat" then "meow"
    when y == "zebra" then "stripes"
    else
      
    "wtf?"
    end 

IMN logo majestic logo threadwatch logo seochat tools logo