Home »
Ruby Tutorial »
Ruby Programs
Ruby program to print numbers from 1 to 5 using for 'until' loop
Last Updated : December 15, 2025
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