Ruby program to demonstrate the upto() function

bookmark

num1 = 5 ;
num2 = -5;

# Prints the number up to 10
num1.upto(10){| i | print i, " "}

print "\n";

# Prints the number up to 1
num2.upto(1){| i | print i, " "}

 


Output:

5 6 7 8 9 10 
-5 -4 -3 -2 -1 0 1