Let's take a look at another example. For the for loop. I'm going to jump to sublime. This is what we want to accomplish this time, find the multiples of six between one and 100. So we want to cycle through the numbers one and 100 and find all the numbers that are multiples of six, meaning they are divisible by six without any remainder. So let's look at how we would do that.
First thing we want to do is create our for loop. Inside the parentheses, we want to declare our variable. I is equal to one because we're counting from one to 100. And you may have noticed that I get used a lot it's very frequently used in a for loop for a counter. Just a common practice. Now we enter our semicolon to separate the parts of the for loop.
Now we need to check the condition. So we are doing what between one and 100. So let's check and see we'll do this loop until I while i is less than one to one. So once it gets above 100, it will exit out. Okay, we could have also done is less than or equal to 100, semi colon, and then we want to increment our variable. Okay, so that will give us the structure of the loop.
Now in order to determine whether a number is divisible by six, we're going to need to divide it by six and see if there is any remainder. And so we need to use the modulus operator for that. So I'm going to create a variable inside this loop. I'm going to use the let keyword this time, the ES six key word. The reason I'm using it in this session Because this variable I'm creating, I'm only going to use inside of this block of code. And let allows us to limit scope and the scope will just be inside this block of code.
So this variable will not be accessible anywhere else. The situation where this might be important in your main code is if you're using a variable name inside of this for loop, and you don't know if you use that variable name before and so you don't want to overwrite something that existed previously. So I'm going to call this variable mod, and I'm going to set it equal to i modulo six. So that's going to put the remainder of I modular six into the mod variable. Now we can use an if statement to see if mod has a remainder. So if my Odd is equal to zero.
If it's equal to zero, we know that the number is divisible by six. And if that's the case, then we want to console dot log. Whoops is a multi multiple of six. Okay, that's our loop. Let's go ahead and save it. And let's see how this works.
Copy the file path, jump out to the browser. Let's display that file and open our console. And look what we've got. We've got a long string of numbers here, 612 1824 3036 4240 850-460-6670 270-884-9096 and all of those are multiples of Next. So it looks like that for loop worked for us. Alright, let's move on to the next concept.