Ruby Control Structures – Infinite Loop Solution

In this post, we will solve Ruby Control Structures – Infinite Loop HackerRank Solution. This problem (Ruby Control Structures – Infinte Loop) is a part of HackerRank Ruby series.

Task

This is a wonderful exercise which explains the concept of infinite loops.

“A hacker practices on HackerRank until getting to a rating of O(1) read as (Oh-one)”

An infinite loop in Ruby is of the form

loop do
end

Use an infinite loop and call the method coder.practice within it and break if coder.oh_one? is true.

break if conditions in Ruby are of the form

if <condition>
    break
end

or a one-liner

break if <condition>  

Solution – Ruby Control Structures – Infinite Loop

# Enter your code here. Read input from STDIN. Print output to STDOUT
loop.each do 
    coder.practice
    break if coder.oh_one?
end
    

Note: This problem (Ruby Control Structures – Infinite Loop) is generated by HackerRank but the solution is provided by CodingBroz. This tutorial is only for Educational and Learning purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *