ADVERTISEMENT
ADVERTISEMENT

Ruby program to print numbers from 1 to 5 using for 'until' loop

Ruby Example: Write a program to print numbers from 1 to 5 using for "until" loop.
Submitted by Nidhi, on December 20, 2021

Problem Solution:

In this program, we will use the "until" loop to print numbers from 1 to 5.

Program/Source Code:

The source code to print numbers from 1 to 5 using for "until" loop is given below. The given program is compiled and executed successfully.

# Ruby program to print numbers from 
# 1 to 5 using for "until" loop

cnt = 1 ;  

until cnt == 6
    print cnt, " "  ; 
    cnt += 1  ;
end

Output:

1 2 3 4 5

Explanation:

In the above program, we created a variable cnt initialized with 1. Then we iterated the "until" loop till the value of cnt reaches 6 and print numbers from 1 to 5.

Ruby Looping 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.