From: Michael Edgar Date: 2011-02-03T14:51:46+09:00 Subject: Re: For Loop with Steps? --Apple-Mail-11-577363561 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=windows-1252 Hi there, If you're on Ruby 1.8.7 or Ruby 1.9+, you can use the Range class's = "step" method with either a for loop, or with blocks: for x in (0..100).step(5) puts x end or (0..100).step(5) do |x| puts x end You can equivalently do 0.step(100, 5) in place of (0..100).step(5) =96 = they're equivalent. If you're on an older version of Ruby, you may only be able to use the = second version there - I don't have an older copy ready to check that though. Not many rubyists use the for loop these days because it has a couple = quirks, but they probably won't trip up a beginner. To find out more, check out the Range class: = http://ruby-doc.org/core/classes/Range.html Good luck! Mike Edgar http://carboni.ca/ On Feb 3, 2011, at 12:41 AM, Thescholar Thescholar wrote: > Hello I'm new here :) >=20 > And I already have a noob question. >=20 > I am wondering how it's possible to iterate through a for loop = statement > by 5 rather than by 1. >=20 > Let's suppose I want to count from 0..100. >=20 > Rather than doing this: > 1,2,3,4,5,6,7,8,9,10....97, 98, 99, 100 >=20 > I would like to count by 5 like this: > 0, 5, 10, 15, 20, 25, 30... 90, 95, 100 >=20 > Anyone knoew how I could achieve this? >=20 > Thank you very much in advance! > And nice to meet you :) >=20 > --=20 > Posted via http://www.ruby-forum.com/. >=20 --Apple-Mail-11-577363561--