- Read Tutorial
- Watch Guide Video
Now, a loop
in programming is a process where you take a collection of data and then you iteratively go through each one of those elements
.
Let's imagine a real-world scenario where you're building out some kind of application. You've called a database, that database has sent you back the set of records, so it could be usernames or anything that you're calling the database for. That is going to be stored in an array
.
Now in order to render those on the page, so if you're building out a web or mobile application, you need to be able to loop
through that collection
. So you would take your collection, and then you would use one of the looping mechanisms
that we're going to talk about.
I'm going to walk through about four or five different options, and I'll talk about when you'd want to use one over the other. At the end of the day, they pretty much all are going to perform the same general purpose; which is to iterate over that collection, and then be able to show that data.
If you're building out a web application, you would iterate over a collection of data, and then you would show those names or that data onto the screen.
That's going to be a very common process, and part of the reason why I saved this looping section to go right after the array and data structures section is specifically because: if you're working with loops, you're almost always going to be doing that in conjunction with an array.
Now that you have a good high-level view on what loops are and when you'd want to use them, let's get into the code and start building them out.