title: Using range.each vs while-loop to work with sequence of numbers in Ruby
body: <p>Total beginner here, so I apologize if a) this question isn't appropriate or b) I haven't asked it properly.</p>
  
  <p>I'm working on simple practice problems in Ruby and I noticed that while I arrived at a solution that works, when my solution runs in a visualizer, it gives premature returns for the array. Is this problematic? I'm also wondering if there's any reason (stylistically, conceptually, etc.) why you would want to use a while-loop vs. a for-loop with range for a problem like this or fizzbuzz. </p>
  
  <p>Thank you for any help/advice!</p>
  
  <p>The practice problem is:</p>
  
  <pre><code># Write a method which collects all numbers between small_num and big_num into 
  an array. Ex: range(2, 5) =&gt; [2, 3, 4, 5]
  </code></pre>
  
  <p>My solution:</p>
  
  <pre><code>def range(small_num, big_num)
    arr = []
    (small_num..big_num).each do |num|
      arr.push(num)
    end
  
    return arr
  end
  </code></pre>
  
  <p>The provided solution:</p>
  
  <pre><code>def range(small_num, big_num)
    collection = []
    i = small_num
    while i &lt;= big_num
      collection &lt;&lt; i
      i += 1
    end
  
    collection
  end
  </code></pre>