Skip to content
the poor coder

Hackerrank Ruby Control Structures - Infinite Loop Solution

Poor Man
Published
Updated
Reading time
1 min read

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

Text
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

Text
if <condition>
    break
end

or a one-liner

Text
break if <condition>  

Solution in ruby#

Approach 1.

Python
loop { coder.practice; break if coder.oh_one? }

Approach 2.

Python
loop do
    coder.practice
    break if coder.oh_one?
end

Keep going

ESC