# If || statements

**URL:** <https://www.ruby-forum.com/t/if-statements/128587>\
**Category:** Ruby\
**Created:** [February 9, 2008, 1:29am UTC](https://www.ruby-forum.com/t/if-statements/128587 "2008-02-09T01:29:36Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2008, 1:29am UTC](https://www.ruby-forum.com/t/if-statements/128587/1 "2008-02-09T01:29:36Z")

</div>

Hey chaps,

Is is at all possible to have a statement such as

p "some string " if ( stuff || more\_stuff || other\_stuff)

–

Regards,

John M.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2008, 1:36am UTC](https://www.ruby-forum.com/t/if-statements/128587/2 "2008-02-09T01:36:38Z")

</div>

John M. wrote:

> Hey chaps,
> 
> Is is at all possible to have a statement such as
> 
> p "some string " if ( stuff || more\_stuff || other\_stuff)

You don’t have to ask. Try it yourself. Start up irb and enter a  
statement:

$ irb  
irb(main):001:0\> x = 2  
=\> 2  
irb(main):002:0\> y = 3  
=\> 3  
irb(main):003:0\> z = “a”  
=\> “a”  
irb(main):004:0\> p “some string” if (x || y || z)  
“some string”  
=\> nil  
irb(main):005:0\>

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2008, 1:40am UTC](https://www.ruby-forum.com/t/if-statements/128587/3 "2008-02-09T01:40:10Z")

</div>

On Sat, 2008-02-09 at 09:28 +0900, John M. wrote:

> Hey chaps,
> 
> Is is at all possible to have a statement such as
> 
> p "some string " if ( stuff || more\_stuff || other\_stuff)

I’m not sure what I’m missing here:

$ irb  
irb(main):001:0\> p “hello” if (false || false || true)  
“hello”  
=\> nil  
irb(main):002:0\> p “hello” if (false || false)  
=\> nil

HTH,

Felix

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 9, 2008, 12:12pm UTC](https://www.ruby-forum.com/t/if-statements/128587/4 "2008-02-09T12:12:12Z")

</div>

On 09.02.2008 01:36, Tim H. wrote:

> You don’t have to ask. Try it yourself. Start up irb and enter a statement:  
> =\> nil  
> irb(main):005:0\>

And you can spare the brackets

irb(main):001:0\> “yes” if false || false || true  
=\> “yes”

Cheers

robert

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 13, 2008, 7:19pm UTC](https://www.ruby-forum.com/t/if-statements/128587/5 "2008-02-13T19:19:38Z")

</div>

Oh sorry, forgot to have a look on the senders, thought you were the one  
who started this thread.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 13, 2008, 2:36pm UTC](https://www.ruby-forum.com/t/if-statements/128587/6 "2008-02-13T14:36:54Z")

</div>

On [Sat, 09.02.2008 09:39], fw wrote:

> I’m not sure what I’m missing here:
> 
> Felix

Uhm, it’s working just the way everybody would expect it to work?  
false or false or true evaluates to true (if i have the choice i of  
course take the best one)  
false or false is just false, as there’s no way to pick true.

---

<div class="post-metadata">

**Author:** ![jmaenpaa](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/9de053/32.png) [@jmaenpaa](https://www.ruby-forum.com/u/jmaenpaa)\
**Post date:** [February 14, 2008, 11:10pm UTC](https://www.ruby-forum.com/t/if-statements/128587/7 "2008-02-14T23:10:44Z")

</div>

|| operator return true if at least one of the operands is true, so:

false || false || true returns true, and hello is printed.

false || false returns false and thus, nothing is printed (nil).

Note: || operator stops evaluating when the first true yielding  
expression is found.

On Fri, 8 Feb 2008 19:39:06 -0500, fw [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
