So suppose that you want to agree john 10 times, would you write console dot log? Hi, john 10 times, that would be definitely a waste of time. So instead of writing the code 10 times by ourselves, we are going to use four loops. And to use a for loop, what you would do is you would just type four, and then you add parentheses, and inside them, you just start by creating an integer that starts by zero. So for example, I'm going to add lit i equals zero, and always in for loop. It's conventional to use AI.
As a variable. You can of course, use any other variable name like x, y, z or anything but it's conventional to use I venue at semi colon and then here you add something called condition. And what condition means is the number of times that you want to Print to print that action or to do that action. And as long as that condition is met, we are going to stay in the loop and do the same over and over again. And once once that condition is violated, we are going to get out of the loop. And in order to do our condition, I am going to use a very simple condition by using I and then smaller than 10.
And what that means is that as long as I is smaller than 10, we want to do the same code that is inside this for loop. And then we want to increase it so here I'm going to add another semicolon and then i plus plus and remember, plus plus means that we are going to increase I by one each single time. So AI is going to start by zero. And then it's going to go all the way to 10. And each time it increases, it is going to do and implement the code that is inside the for loop. And here I'm going to add, and then inside that loop, you should add the code that you want it to be implemented, as long as this condition is met.
So here what I'm going to do, I'm going to just use the console dot log, and then I'm going to add hi john inside it. Hi, john. And semicolon. Now if I save and run our program, as you can see here on the console, we have 1-234-567-8910. We have a hydrant 10 times printed on our screen 10 times instead of just writing this code 10 times We can just write as you can see 123 lines of code that has generated this output instead of writing the same code over and over and over again. And by the way, that will be very, very useful when you are dealing with a much complicated code in instead of writing the same code over and over again, you just need to use for loop and the job is done.
So to recap, for loops are used to repeat a specific code many times as long as the condition is met.