ADVERTISEMENT
ADVERTISEMENT

Ruby program to demonstrate the downto() function

Ruby Example: Write a program to demonstrate the downto() function.
Submitted by Nidhi, on December 12, 2021

Problem Solution:

In this program, we will demonstrate the downto() function. The downto() function returns all the numbers less than equal to the number till the specified number.

Program/Source Code:

The source code to demonstrate the downto() function is given below. The given program is compiled and executed successfully.

# Ruby program to demonstrate the 
# downto() function

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

Explanation:

In the above program, we created two integer variables num1, num2 that are initialized with 5, -5 respectively. Then we called the downto() function and printed numbers in decreasing order till the specified number.

Ruby Basic Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.