JavaScript Lingo: Loops


If there's a set of data, (we'll use an array for this example, but it doesn't have to be,) and you want to perform the same manipulation to every piece in that set of data, you can use something called a loop.

Loops have some complex syntax to get used to at first, but once you have it, they're extremely useful. I used loops in many of my algorithm solutions.

You don't need to understand everything here - just know that loops exist when you need to traverse a set of data and they can cut down on the amount of code you need to write.

如果有一组数据, (我们将会以数组为例,但这并不是必须的,) 并且你想对数组中的每个元素应用相同的操作, 你可以使用循环

循环的语法对新手来说可能很复杂, 但是一旦你掌握它,它们会特别有用. 我在许多算法解决中应用了循环。

你不必理解这里的所有一切 - 只需要知道当你想要处理一组数据时,循环可以大幅度减少你的工作量就好。