# What does the step() method do

**URL:** <https://www.ruby-forum.com/t/what-does-the-step-method-do/172848>\
**Category:** Ruby\
**Created:** [July 28, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/what-does-the-step-method-do/172848 "2009-07-28T21:14:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 28, 2009, 9:14pm UTC](https://www.ruby-forum.com/t/what-does-the-step-method-do/172848/1 "2009-07-28T21:14:22Z")

</div>

I have to write a program to implement the Sieve of Erastosthenes  
algorithm for finding the prime nos.  
I got the following code on [scriptol.org](http://scriptol.org)

top = 100  
sieve = []  
for i in 2 … top  
sieve[i] = i  
end

for i in 2 … Math.sqrt(top)  
next unless sieve[i]  
(i\*i).step(top, i) do |j|  
sieve[j] = nil  
end  
end  
puts sieve

Can someone please tell me what’s happening in the lines  
next unless sieve[i]  
(i\*i).step(top,i) do |j|  
sieve[j]=nil

---

<div class="post-metadata">

**Author:** ![prateekagarwal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/b38774/32.png) [@prateekagarwal](https://www.ruby-forum.com/u/prateekagarwal)\
**Post date:** [July 28, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/what-does-the-step-method-do/172848/2 "2009-07-28T21:45:22Z")

</div>

0.step(8, 3) do |i|  
puts i  
end

–output:–  
0  
3  
6
