What does the step() method do

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

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

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

–output:–
0
3
6

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs