title: Looping differences in Ruby using Range vs. Times
body: <p>I'm trying to solve a Project Euler problem using Ruby, I used 4 different looping methods, the for-loop, times, range and upto method, however the times method only produces the expected answer, while the for-loop, range and upto method does not. I'm assuming that they are somewhat the same, but I found out it's not. Can someone please explain the differences between these methods?</p>
  
  <p>Here's the looping structure I used</p>
  
  <pre><code># for-loop method
  for n in 0..1
    puts n
  end
  
  0
  1
  =&gt; 0..1
  
  # times method
  2.times do |n|
    puts n
  end
  
  0
  1
  =&gt; 2
  
  # range method
  (0..1).each do |n|
    puts n
  end
  
  0
  1
  =&gt; 0..1
  
  # upto method
  0.upto(1) do |n|
    puts n
  end
  
  0
  1
  =&gt; 0
  </code></pre>