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.
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.
Output:
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.
need an explanation for this answer? contact us directly to get an explanation for this answer