title: Why this code become an infinite loop without using lambda as condition parameter
body: <p>I'm reading Programming with Ruby 2.0 and have a question   </p>
  
  <pre><code>   def my_while(cond, &amp;body)
       while cond.call
         body.call
       end
     end
  
     a=0
  
     my_while -&gt; { a &lt; 3 } do
       print a
       a += 1
     end #=&gt; 0 1 2
  </code></pre>
  
  <p>I so the question is: why we can not use the method this way</p>
  
  <pre><code>    def my_while(cond, &amp;block)
        while cond
         block.call
        end   
      end
  
      a = 0
      my_while (a&lt;3) do
        print a
        a += 1
      end #=&gt; infinite loop
  </code></pre>
  
  <p>And actually how to use this function with condition (a&lt;3) and a block parameter?</p>
  
  <p>P.S. I saw <a href="https://stackoverflow.com/questions/6945891/why-is-the-parameter-of-this-method-a-lambda-and-how-does-it-work">this question</a> but still can't comment there to ask!</p>