hi! i dont know, how the syntax for a switch-case loop, works. i tried something like: x = 1 switch(x) case 1: return "bla bla" case 2: return "hoho" end but nothing. im sure is very easy, but i have no idea how the syntax is. can anyone help? ty!! -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Wrong words, though it''s quite easy to go look this kind of stuff up in
any
Ruby documentation (Pragmatic Ruby Guid comes to mind).
Here''s the syntax:
case expr
[when expr [, expr]...[then]
expr..]..
[else
expr..]
end
Jason
On 8/26/06, vincent vega
<rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org>
wrote:>
>
> hi!
> i dont know, how the syntax for a switch-case loop, works.
>
> i tried something like:
> x = 1
> switch(x)
> case 1: return "bla bla"
> case 2: return "hoho"
> end
>
> but nothing. im sure is very easy, but i have no idea how the syntax is.
>
> can anyone help? ty!!
>
> --
> Posted via http://www.ruby-forum.com/.
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
try case x when 1: when 2: else end it, er, is in the manual... allbests, ........................................................................ .......... John Browning On 26 Aug 2006, at 14:08, vincent vega wrote:> > hi! > i dont know, how the syntax for a switch-case loop, works. > > i tried something like: > x = 1 > switch(x) > case 1: return "bla bla" > case 2: return "hoho" > end > > but nothing. im sure is very easy, but i have no idea how the > syntax is. > > can anyone help? ty!! > > -- > Posted via http://www.ruby-forum.com/. > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
vincent vega wrote:> hi! > i dont know, how the syntax for a switch-case loop, works. > > i tried something like: > x = 1 > switch(x) > case 1: return "bla bla" > case 2: return "hoho" > endYou want: case x when 1 return "bla bla" when 2 return "hoho" end For more info, see: http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html#S5 Chris --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---