[MUSIC] Hi and welcome back. In our last lesson, we were talking about JavaScript loops and in this lesson we'll continue that example and look at one additional type of loop. Last time I typed in the string Fred Smith. I wanted to emphasize that when we use strings in a programming language. You can consider them something like a numbered list of letters. Where the first letter in this case the f is at position zero. And the second letter is at one. And so forth and so I sting Fred Smith has positions zero through nine. So, when we do our loop and we have while i is less than fullname.length, i starts at zero. And at zero it's less than the entire length. On the next iteration of the loop I is increased by 1 and i is still less than the length but eventually, i will reach the length and it will pull stop. As it libiterates, i takes on the value of each letter position right here where my cursor is. And so we get the letters, like this output vertically. Because after each letter, there's a break. So, that's the while loop. Let's consider another kind of loop. So here we have the code for a form example that we looked at previously. But I've added something new to it. Near the bottom, I've added a div with an ID form elements. Let's look at this. So this is our form that we've used before, and I'll continue using my test name. And we'll click calculate and we've seen this output before but what's at the bottom is new and this is where I put Could do it with the form elements ID. Notice that was happening here is we're getting information about each field in the form. You know this information really isn't useful for somebody users but it could be useful for us. Here we've got firstName, lastName, phone, quantity, price, and total, which are the names of these inputs. They're all of type text, and at the moment they all have these values. Now the way I did this is with a loop. And we go look at that loop. It's here called display form values starting on line 69. And in this case our loop is not a while loop but instead a for loop starting on line 73. It has the key word for A variable I that starts with a value of zero. I is less than a elem.length. And element here on line 72 is all of the elements in the form document .getElementById, widgetForm .elements. And widgetForm is the name of our form. So in this case the variable, online sent me two, is the entire collection of the form elements. And this for loop allows us to go through them one by one. So for each element we go through in the for loop, we're getting the information that you saw in the output. So, many times in a programming language, we're dealing with collections of things. In this case, we have a collection of form elements. In our previous example, we had a collection of letters that was a string. And when we want to work with these collections, we will frequently use a loop to go through the elements of the collection. One by one, that is letter by letter, or form element by form element, or any number of things in order through a loop. And the two most common loops for us to use are the while loop In a for loop. Now actually we could use either a for loop or a while loop for every case. You really don't need to form more types of loops. But sometimes one is a little more convenient than the other. So we tend to have a few varieties. With the while and for being the most common. So the best way to learn loops is to practice with them. Try reproducing these examples and see how they go for you. In our next lesson, we'll be doing guided practice for our HTML form and form validation.