Do while loops in Ruby

I’ve been programming in Ruby for almost a year now and I had no clue this existed. I came across this when I was looking at how best to emulate a do while loop in Ruby. Apparently there is a do-while structure in Ruby, based on my learning from Jeremy Voorhis’ blog post

Here is how it works

     i = 10
     puts i
     i -= 1
end while(i > 1)

This has been another “holy crap how come I did not know this moment”.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s