Hello, in this JavaScript video, I am going to show you loops and more specifically the for loop. So what is a loop, if you haven't already guessed is essentially a little feature in programming that allows you to run a piece of code several times without having to write that code several times. So let me show you a for loop. So use a keyword for open closed brackets in here, there are three main parts and these parts are separated by semicolons. The first part is the sort of set of initialization stage. So unless any variables that you're using for the loop you would set up and create here, say var, I pass 32 zero by default, and the next step is the condition.
So you can think of this as a comparison operator. So they is where you would put something like that. So this is the condition while this condition is true, the loop will continue running. And this condition I'll say 100. And so that means once I hit 100 or above, the loop will stop. And this little part here is called the iteration statement.
And this essentially is a piece of code that is run after each single pass of the for loop. So for this would say i plus plus, what this is going to do is add one to it. And we could do something called well, but let's just do it for now. And then you put curly braces, everything within these curly braces will be run as a part of the fold. Okay, so let's simply use console dot log. This is console log boy reload.
You yet. Okay, so what's happened is logged at zero to 99. My thinking, Okay, zero is starting at zero. Why did it stop at 99? The reason is, so what it does, it starts zero console, logs it and he adds one to it. So it is now one and 234 all way to 9899.
But when he adds one to 99, and it becomes 100. Remember after every single pass of the whole loop, this condition is checked. So when he said is not is 99 less than 100. Yes, that's the reason this is printed out. Once one is added to it 100 now, so it's a is 100 less than 100. Now it isn't the same, so it doesn't print it out.
What you could do is put less than or equal to, and this law printed out from zero to 100. Let's change this or slightly, so we do something. Let's do something like this. So we just timed it. 1.5 every single time see what we get Okay, we hit an infinite amount for loop. So what happened?
It's not like this at all for some reason that we try fluffy balls Okay, still does not like that. Run that it is okay. Okay, so that is fine. One plus equals 10 Why did the times equals not order Okay, so time is equal didn't seem to work here for some reasons a plus equals works that I did not know. So I've learned something new. Wow.
Okay, so for not letting me do anything with Crump. Luckily for us, we are and let's see if I can get this closed down, close that down. change this back to a plus. Okay, so if interested, I didn't know that and learn something new. Go back inspector is added to it till it hit the condition. And in here, you can do whatever you want.
So we could print something out and say something like, this is Vishal. I reload it say he says this position zero to four. And you know, you could be storing in the database, it could be a game where you're moving a character around the screen, you can absolutely do whatever you want. So that's the for loop. The only questions, feel free to pop me a message. There'll be a link to the GitHub page, which contains all the source code from every single tutorial in this series.
And as usual, thanks for watching. I look forward to seeing you in the next video.