Ruby program to demonstrate the downto() function

bookmark

num1 = 5 ;
num2 = -5;

# Prints the number down to 1
num1.downto(1){| i | print i, " "}

print "\n";

# Prints the number down to -10
num2.downto(-10){| i | print i, " "}

 


Output:

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