# What's a real world example for using loop?

**URL:** <https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678>\
**Category:** General\
**Created:** [July 9, 2020, 11:15am UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678 "2020-07-09T11:15:39Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozee1z](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@ozee1z](https://forum.freecodecamp.org/u/ozee1z)\
**Post date:** [July 9, 2020, 11:15am UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/1 "2020-07-09T11:15:39Z")

</div>

I have been learning loops for a while now and its gets trickier every now and then lol 😃. I would love to know some real world examples for using loops.

---

<div class="post-metadata">

**Author:** ![Sky020](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/sky020/32/128093_2.png) [@Sky020](https://forum.freecodecamp.org/u/Sky020)\
**Post date:** [July 9, 2020, 11:48am UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/2 "2020-07-09T11:48:36Z")

</div>

Hello there,

I am not sure what you are hoping to see, but have a peruse through the freeCodeCamp GitHub repo: [https://github.com/freeCodeCamp/freeCodeCamp/blob/master/curriculum/test/test-challenges.js#L180](https://github.com/freeCodeCamp/freeCodeCamp/blob/master/curriculum/test/test-challenges.js#L180)

You will struggle to find them, as we mostly make use of higher-order functions (which make use of `for` loops).

Have fun.

---

<div class="post-metadata">

**Author:** ![selectiveduplicate](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/selectiveduplicate/32/154483_2.png) [@selectiveduplicate](https://forum.freecodecamp.org/u/selectiveduplicate)\
**Post date:** [July 9, 2020, 1:18pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/3 "2020-07-09T13:18:40Z")

</div>

Programmatically? Well, using loops we can find the result of any geometric or arithmetic series (unless it’s infinite). If you’re talking about a real-world software application, then how about ATM machines? You type in for a specific amount and until that specific amount is reached the machine continues dispensing you notes.

---

<div class="post-metadata">

**Author:** ![hjanday](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/hjanday/32/167591_2.png) [@hjanday](https://forum.freecodecamp.org/u/hjanday)\
**Post date:** [July 9, 2020, 1:34pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/4 "2020-07-09T13:34:54Z")

</div>

A real life example of a loop could be your music playlist. While you have a song that’s available to be played, it will keep going through your song list and stop when there is no more music that can be listened to.

---

<div class="post-metadata">

**Author:** ![ozee1z](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@ozee1z](https://forum.freecodecamp.org/u/ozee1z)\
**Post date:** [July 9, 2020, 3:11pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/5 "2020-07-09T15:11:02Z")

</div>

Thank you @Sky020 for this GigHub repo, I would check it out.

---

<div class="post-metadata">

**Author:** ![ozee1z](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@ozee1z](https://forum.freecodecamp.org/u/ozee1z)\
**Post date:** [July 9, 2020, 3:12pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/6 "2020-07-09T15:12:58Z")

</div>

hahaha @selectiveduplicate the ATM machine is a great one, never have I thought about it that way. Thank you.

---

<div class="post-metadata">

**Author:** ![ozee1z](https://avatars.discourse-cdn.com/v4/letter/o/0ea827/32.png) [@ozee1z](https://forum.freecodecamp.org/u/ozee1z)\
**Post date:** [July 9, 2020, 3:14pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/7 "2020-07-09T15:14:58Z")

</div>

wow @hjanday hahaha thank you. I am beginning to appreciate the use of loops more and more now.

---

<div class="post-metadata">

**Author:** ![ArielLeslie](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/arielleslie/32/264841_2.png) [@ArielLeslie](https://forum.freecodecamp.org/u/ArielLeslie)\
**Post date:** [July 9, 2020, 5:30pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/8 "2020-07-09T17:30:55Z")

</div>

We use loops (or methods that have loops under the covers) all the time. We are very often dealing with a list of things and we need to repeat the same behavior for each one. A quick search showed that we have 26 basic `for` loops in a relatively small project.  
 ![screenshot](https://global.discourse-cdn.com/freecodecamp/original/3X/1/9/1955abdb38621ad90277a1a1696c3578c8a8e763.png)

---

<div class="post-metadata">

**Author:** ![godswill199](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/godswill199/32/166599_2.png) [@godswill199](https://forum.freecodecamp.org/u/godswill199)\
**Post date:** [July 10, 2020, 2:41pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/9 "2020-07-10T14:41:53Z")

</div>

Instead of inputting/adding a value manually we use the loop to return that value as many times as possible so you don’t have to write a particular text manually over 50 times or more. An example can be the list you of songs you have on your music app. Each time a new music is added we output a new line of div or paragraph. I Hope this helps

---

<div class="post-metadata">

**Author:** ![saadanerdetbare](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/saadanerdetbare/32/106470_2.png) [@saadanerdetbare](https://forum.freecodecamp.org/u/saadanerdetbare)\
**Post date:** [July 16, 2020, 10:03am UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/10 "2020-07-16T10:03:59Z")

</div>

An example from my world is that I have made a powershell script that fetches users from Microsoft Active Directory into a list, loops through that list and, based on usernames adds them to different security groups for mapping a home directory  
/Jakob

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:46pm UTC](https://forum.freecodecamp.org/t/whats-a-real-world-example-for-using-loop/408678/11 "2021-06-01T18:46:59Z")

</div>

Closed on June 1, 2021, 6:46pm UTC


