DEV Community

Oscar Ore
Oscar Ore

Posted on

1

Looping: It's all about Repetition!

  • Understanding Looping is a key part of learning how to program. Looping occurs when you tell the program to do a task or something a certain number of times. The decisions are completely up to you. Pretty neat right? There are many types of Looping methods out there but the key takeaway here is that looping allows us to abstract away the actual mechanics of enacting the same lines of code a certain number of times. Here is an example of a loop using the .times method. Check it out:

8.times do
puts “Hey guys! My name is Oscar and I am going to repeat myself eight times.”
end

If you copy and paste the code snippet into IRB in your terminal and hit enter, you should see the following:

Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times
Hey guys! My name is Oscar and I am going to repeat myself eight times

Image of Datadog

The Essential Toolkit for Front-end Developers

Take a user-centric approach to front-end monitoring that evolves alongside increasingly complex frameworks and single-page applications.

Get The Kit

Top comments (0)

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up