In this program, we will demonstrate the upto() function. The upto() function returns all the numbers greater than equal to the number till the specified number.
The source code to demonstrate the upto() function is given below. The given program is compiled and executed successfully.
# Ruby program to demonstrate
# the upto() function
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
Explanation:
In the above program, we created two integer variables num1, num2 that are initialized with 5, -5 respectively. Then we called upto() function and printed numbers in increasing order till specified number.
Program/Source Code:
The source code to demonstrate the upto() function is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created two integer variables num1, num2 that are initialized with 5, -5 respectively. Then we called upto() function and printed numbers in increasing order till specified number.
need an explanation for this answer? contact us directly to get an explanation for this answer