This content originally appeared on DEV Community and was authored by Jahkamso
Imagine you're in a hall (a ball room), all the chairs are disorganised, and your task is to arrange them. Where would you start? Obviously, you'll either go row by row or column by column, but it's going to be sequential/orderly.
The same is true when it comes to "for loops". It's basically a way to go through a list of data and present them one after the other till you get to the end.
An example of "for loops":
const fruits = ["Apple", "Banana", "Cherry", "Date", "Elderberry"];
for (let i = 0; i < fruits.length; i++) {
console.log(fruits[i]);
}
In the example above, there's an array of data containing fruit names. The "for loop" goes through all of them and prints them out in the console, one after the other.
This explanation is short, but I hope you understand "for loops" better.
This content originally appeared on DEV Community and was authored by Jahkamso
Jahkamso | Sciencx (2024-08-23T18:45:58+00:00) What are “for loops” in JavaScript?. Retrieved from https://www.scien.cx/2024/08/23/what-are-for-loops-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.