Subject: case when when
From: Ken Bloom
Date: 11/12/2007 1:08:24 PM
Martyn <martyn.jago@triteq.com> wrote:
> when 5: , 9:
No.
case x
when 5:
#do blah
when 7,9:
#do blah blah
else
end
> -----Original Message-----
> From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf
> Of Shuaib Zahda
> Sent: 12 November 2007 11:38
> To: ruby-talk ML
> Subject: case when when
>
> Hi all
>
> I am just wondering how can we make two cases belong to the same bunch
> of code. I tried to do it like c but it did not work. it is like this in
> c
>
> switch(x)
> {
> case 5:
> #do bla bla
> break;
> case 7 : case 9:
> #do bla bla
> break;
> default:
> #bla
> }
>
> however, I tried to do the same way in ruby but it did not work.
> case x
> when 5:
> #do bla
> when 7: when 9:
> #do bla bla
> else
> #bla
> end
>
> I know that when provides conditions and I can use them but I am just
> wondering what is the way because i did not find it in books and online
>
> regards
> --
> Posted via http://www.ruby-forum.com/.
--
Ken Bloom. PhD candidate. Linguistic Cognition Laboratory.
Department of Computer Science. Illinois Institute of Technology.
http://www.iit.edu/~kbloom1/
|