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

Hostinger image

Get n8n VPS hosting 3x cheaper than a cloud solution

Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.

Start now

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay