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 »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.