Q:

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

belongs to collection: Ruby Looping Programs

0

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

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

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.

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Ruby program to create an infinite loop using \�... >>
<< Ruby program to demonstrate the nested \'do\&...