title: Ruby's && operator
body: <p>In PHP, this evaluates to <code>true</code>:</p>
  
  <pre><code>$a = 1
  $b = 2
  
  var_dump($a &amp;&amp; $b); // true
  </code></pre>
  
  <p>In ruby, this evaluates to <code>2</code>:</p>
  
  <pre><code>a = 1
  b = 2
  p a &amp;&amp; b # 2
  </code></pre>
  
  <p>Why does ruby return the value of the last statement (when the first is true and the second one is also true) and does not return a boolean?</p>
  
  <p>I have two arrays and I iterate them with an external iterator:</p>
  
  <pre><code>a = [1,2,3].to_enum
  b = [5,6,7].to_enum
  c = []
  
  begin
    while a_next = a.next &amp;&amp; b_next = b.next
      result = a_next + b_next
      p "a[x] + b[x] = c[x] = #{a_next} + #{b_next} = #{result}"
      c &lt;&lt; result
    end
  rescue 
    p c
  end
  </code></pre>
  
  <p>The condition: <code>while a_next = a.next &amp;&amp; b_next = b.next</code> sets <code>a_next = b_next</code> (the first question seems related to this behavior, I think).
  But when I wrap the two <code>&amp;&amp;</code> operands, it works as expected: <code>(a_next = a.next) &amp;&amp; (b_next = b.next)</code>.</p>