Method: Numeric#step

Defined in:
lib/source/ruby.rb

#step(limit, step) ⇒ Object

call-seq:

num.step(limit, step ) {|i| block } -> num

Invokes block with the sequence of numbers starting at num, incremented by step on each call, then returns self. The loop finishes when the value to be passed to the block is greater than limit (if step is positive) or less than limit (if step is negative).

1.step(5, 2) { |i| puts i }
Math::E.step(Math::PI, 0.2) { |f| puts i }

produces:

1
3
5
2.71828182845905
2.91828182845905
3.11828182845905


4572
4573
4574
4575
4576
# File 'lib/source/ruby.rb', line 4572

def step(limit, step)
  `var i=this.valueOf()`
  `if(step>0){if(i<limit){for(;limit>=i;i+=step){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':i-=step;break;default:throw(e);};};};};}else{if(i>limit){for(;limit<=i;i+=step){try{#{yield `i`};}catch(e){switch(e.__keyword__){case 'next':break;case 'break':return e.__return__;break;case 'redo':i-=step;break;default:throw(e);};}};;};}`
  return self
end