Hello, in this JavaScript video, I am going to show you the do while loop. So that the for loop The while loop right here, if any of this seems alien to you, I highly recommend going and checking out for loop and the while loop videos. So what's a do while loop, they do while loop very similar to one, but it is run once at the very least, then the condition is checked. So a for loop and a while loop have this condition right here. And this is checked at the start of you know running the loop every single time. And if it's valid, that it runs it, if not, then he doesn't really wear the do while loop the condition is checked at the end.
So he will get run at least once. And if we simulate something very similar, we're using a do while loop. If we do var x all ij that's UK equals zero and then the format you do and So the rest of it apart from the condition where that is checked in the same as the while loop, and then you just put here while and now you put your condition to say k less than or equal to 100. Save that refresh. And you might think, okay, produce exact same results, or how is this any different at the moment? It isn't, look what happened if I change this to a payment, and the condition stays only run this for loop.
If I eat less than 100. At the start, it's 1000. So it's not going to run it. J will set to 1000. And we'll set k as well. Okay, let's reload it.
As you can see, you get one Princeton with one blog. statement, it says this is position 4k 1000. So what's happened in the fold, or if 1000, the condition is less than or equal to 100,000 is not much bigger than 100. Therefore, this will get run j in the thousand, the condition for the wall loop is if j less than or equal to 100. Now, 1000 again is, you know, bigger, so this loop is one K is set to 1000. But here, it runs this piece of code, which you know, to this right here, then it checks the condition is k less than 100.
So is 1000 I mean less than or equal to 100. So, is the thousand less than or equal to 100. Now, it isn't it's much bigger and then it doesn't run anymore, but it runs the code at least once. So, if you need to do this a one note if you have some code and you know you need to at least run it once, maybe some sort of check some sort of impact. from the user. So this is great if you're getting input from the user.
And this condition is used to check if the input is valid or not. So if the user provide some invalid input, you know, keep asking them till they provide valid input. This is fantastic so that they do while loop. These are the main loops that you will be dealing with. If you have any questions, feel free to pop me a message and I look forward to seeing you in the next video.