Syntax switch

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!!

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

try

case x
when 1:
when 2:
else
end

it, er, is in the manual…

allbests,



John B.

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

You 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