# Question about case statement

**URL:** <https://www.ruby-forum.com/t/question-about-case-statement/168416>\
**Category:** Rails\
**Created:** [May 20, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/question-about-case-statement/168416 "2009-05-20T16:57:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pesho318i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pesho318i](https://www.ruby-forum.com/u/pesho318i)\
**Post date:** [May 20, 2009, 4:57pm UTC](https://www.ruby-forum.com/t/question-about-case-statement/168416/1 "2009-05-20T16:57:08Z")

</div>

hello,

i’d like to combine to clauses of my case statement, and I do this:

case check  
when value1  
//do something  
when value2  
//do something (the same as in the first when)  
end

But how can I combine the two “when”-s. It is redundant to write the  
same code to “do something”

I tried to find the syntax, but couldn’t.  
I tried something like:

case check  
when value1  
when value2  
//do the thing  
end

but this only works when check = value2

Thanks!

---

<div class="post-metadata">

**Author:** ![pesho318i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pesho318i](https://www.ruby-forum.com/u/pesho318i)\
**Post date:** [May 20, 2009, 5:03pm UTC](https://www.ruby-forum.com/t/question-about-case-statement/168416/2 "2009-05-20T17:03:46Z")

</div>

On Wed, May 20, 2009 at 04:57:08PM +0200, Pesho P. wrote:

> end
> 
> But how can I combine the two “when”-s. It is redundant to write the  
> same code to “do something”  
> […]

case check  
when value1, value2  
//do something  
end

> Thanks!  
> –Greg

---

<div class="post-metadata">

**Author:** ![pesho318i](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/ec9cab/32.png) [@pesho318i](https://www.ruby-forum.com/u/pesho318i)\
**Post date:** [May 20, 2009, 6:57pm UTC](https://www.ruby-forum.com/t/question-about-case-statement/168416/3 "2009-05-20T18:57:26Z")

</div>

Thanks, Greg!
