Hackerrank Ruby Control Structures - Infinite Loop Solution
1 min read

Hackerrank Ruby Control Structures - Infinite Loop Solution

Hackerrank Ruby Control Structures - Infinite Loop Solution

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 in ruby

Approach 1.

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

Approach 2.

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

Enjoying these posts? Subscribe for more


Adblocker detected! Please consider reading this notice.

We've detected that you are using AdBlock Plus or some other adblocking software which is preventing the page from fully loading.

That's okay. But without advertising-income, we can't keep making this site awesome.

We don't have any banner, Flash, animation, obnoxious sound, or popup ad. We do not implement these annoying types of ads!

We need money to operate the site, and almost all of it comes from our online advertising.

Please add thepoorcoder.com to your ad blocking whitelist or disable your adblocking software.

×