From the course: Learning the JavaScript Language

Unlock the full course today

Join today to access over 24,400 courses taught by industry experts.

While loops

While loops

- [Instructor] In this video, we're going to talk about one more way of looping called the while loop. I have two loops here. One is a sequential for loop, and the second one is a while loop. These basically do exactly the same thing, to prove that I'll copy this and paste it into Node, and so as we can see we're iterating from zero to nine. Just logging out a message each time. I'm going to clear that with control L, and then we'll do the same thing with this Y loop, except in this case, I'm setting a counter separately. We're going to copy and paste this first, just to prove what we're doing. We start at zero and go all the way up to nine. So in this case, it looks like I'm basically sort of breaking apart the pieces of this for loop, where I initialize my counter, and then I say while and in parentheses I have my condition, at which point I'm going to stop. I do some stuff including changing my counter, and this will…

Contents