There is a third loop in JavaScript called do while loop. And what the do while loop does is that it executes the code at least once, regardless of the condition. So for example, if we take a look at the do while loop, I'm going to comment these out first. And I'm going to create a do while loop until you either do while loop. What you are going to do is you just create do and then curly braces, and then inside those do inside those curly braces, you add your code, and then you type while and then the condition and cynical. So the condition here should be for example, it could be three at first, a variable called x ln x equals 10.
Right? And then here inside the while loop, I'm going to add if x is smaller than 10. As you can see here, the condition is violated because x equals to 10. But here says if x is smaller than 10. and here if I add a code like console dot log, and then Hi, john, john, and if I save and run, I am going to get hi john, only once because it's first going to get to the do loop, do condition and implement this code and then it is going to take a look at the while loop. If the while loop is met, if the while loop condition is met, it's going to go back again and excute what is inside the do curly braces, but if the condition is violated will not continue and it's gonna move on and get out of the loop. So for example, if I change the value of x from 10 to zero, and then here I increase the x by one x plus plus, and if I save and run, I am going to get x, I am going to get hi john printed out on the screen 10 times, because here it does the same to it's gonna get executed, this code is going to get executed 10 times because it was going to get into the do and print out this line of code and then it's going to increase the value of x.
And then it's going to get to the wild loop and check the condition if the condition is still there. It is is still met, we are going to get again back to the do condition or the do code and implement the code again and increase x and so on and so forth. So do why loops get executed at least once.