upto(p1)
public
Iterates block, passing in integer values from int up to
and including limit.
5.upto(10) { |i| print i, " " }
produces:
5 6 7 8 9 10
Show source
/*
* call-seq:
* int.upto(limit) {|i| block } => int
*
* Iterates <em>block</em>, passing in integer values from <i>int</i>
* up to and including <i>limit</i>.
*
* 5.upto(10) { |i| print i, " " }
*
* <em>produces:</em>
*
* 5 6 7 8 9 10
*/
static VALUE
int_upto(from, to)
VALUE from, to;
{
RETURN_ENUMERATOR(from, 1, &to);
if (FIXNUM_P(from) && FIXNUM_P(to)) {
long i, end;
end = FIX2LONG(to);
for (i = FIX2LONG(from); i <= end; i++) {
rb_yield(LONG2FIX(i));
}
}
else {
VALUE i = from, c;
while (!(c = rb_funcall(i, '>', 1, to))) {
rb_yield(i);
i = rb_funcall(i, '+', 1, INT2FIX(1));
}
if (NIL_P(c)) rb_cmperr(i, to);
}
return from;
}