# If statement with multiple conditions

**URL:** <https://rubytalk.org/t/if-statement-with-multiple-conditions/43699>\
**Category:** ruby-talk\
**Created:** [11 January 2008 14:39 UTC](https://rubytalk.org/t/if-statement-with-multiple-conditions/43699 "2008-01-11T14:39:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Katsuo\_Isono](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@Katsuo\_Isono](https://rubytalk.org/u/Katsuo_Isono)\
**Post date:** [11 January 2008 14:39 UTC](https://rubytalk.org/t/if-statement-with-multiple-conditions/43699/1 "2008-01-11T14:39:33Z")

</div>

Hi, I am pretty new to programming. What is the good way to write the  
following condition.

def cart  
if request.post and @cart.size \< 10  
&nbsp;&nbsp;puts "order accepted"  
else  
&nbsp;&nbsp;redirect\_to :action =\> 'list'  
end  
end

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Sebastian\_Hungereck1](https://avatars.discourse-cdn.com/v4/letter/s/3ab097/32.png) [@Sebastian\_Hungereck1](https://rubytalk.org/u/Sebastian_Hungereck1)\
**Post date:** [11 January 2008 15:18 UTC](https://rubytalk.org/t/if-statement-with-multiple-conditions/43699/2 "2008-01-11T15:18:40Z")

</div>

Katsuo Isono wrote:

> Hi, I am pretty new to programming. What is the good way to write the  
> following condition.
> 
> def cart  
> if request.post and @cart.size \< 10  
> &nbsp;&nbsp;puts "order accepted"  
> else  
> &nbsp;&nbsp;redirect\_to :action =\> 'list'  
> end  
> end

That's a perfectly reasonable way to write it.

> **···**
>
> --  
> Jabber: sepp2k@jabber.org  
> ICQ: 205544826

---

<div class="post-metadata">

**Author:** ![Katsuo\_Isono](https://avatars.discourse-cdn.com/v4/letter/k/977dab/32.png) [@Katsuo\_Isono](https://rubytalk.org/u/Katsuo_Isono)\
**Post date:** [12 January 2008 07:49 UTC](https://rubytalk.org/t/if-statement-with-multiple-conditions/43699/3 "2008-01-12T07:49:36Z")

</div>

Thanks Sebastian. It worked. What was I thinking?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
