In this Celexa we learn quickly about the for loop while loop and do a loop in the javascript.
So first of all you have to learn about what these loops so loops are used to iterate the piece of a
core using for a while.
Do While as we have already said that we have three types of loop in the case of a java script.
So what if I just say you that these lists.
Print me your name or you can console log your name.
In my case that is such in and let me say something that you have to just print this.
That is how it in time.
So if you don't know about the loop you have to simply copy paste copy paste it told in time and it
is very tedious tasks.
So instead what do you can do is make use of the loop.
So we have for loop while loop do while loop and therefore in loop but we'll just start from for loop.
So first of all javascript for loop.
It did it that element for the fixed number of our times it should be use if number of iteration is
known.
So let's see the syntax first.
So you have to make use of this for the keyword in all lowercase and first here is the initialization
and just give these semicolon after each of these bark.
So next one would be your condition should we condition and just give another semicolon and they can
demand or update.
You can also so that this is update.
So after this you have to dispute your.
This is the scope and here you have the code to be executed so you can see.
This is the way in order to create the for loop.
So let's take a small example in order to see how these for loop work in the real life.
So let me just create this script over here using this for loop and I have said that first one is initialization.
So let me just create one variable and give this value to be one.
So this is your initialization and basically you'll make use of these VAR keyword in order to create
any variable initialization.
Next one is your condition.
Same age we have done in the case of if else condition and I'll make use of these and next Tony or update
or the increment.
So let me just write it quickly and show you what is happening over here so I'll just say consolidate
log which was our name which I just give you the example a minute before.
So if I this close this so you can simply see over here what we have done is we have created the for
loop using this the syntax which is initialization and for every initialized note for every loop it
to just check for this condition.
So here you have to this print your name which is such in this case five times because if this condition
is false it will start minute this loop and you can see we have the update over here saying that in
every loop you have to increase the value of 1.
So first it will be 1 and it will just take the condition if one is less called a 5 which is true.
That means it will this into this scope and it will just print sergeant first first time and then the
next.
It will just increase the value of IE.
It will be 2 and it will again check for the condition 2 is lesser equal to 5 which is true again it
will this interim 2.
This is scope in print such in again.
Again it will increase the value of y and when the value of I would be 5 it will just take again this
condition 5 is the lesser equal to 5 which is again true because 5 is equal to 5.
It will just print such in again and in the next it will make 6 and it the stick again the 6 is lesser
equal to 5 which is false it will terminate this loop and print as the names such in that these your
5 times so you can see over here.
We just made the use of these sets in and you can see it is 5 over here.
That means you have just made use of this loop in order to print your name five times.
So this is your simple for loop.
Where do you have initialization condition ending remain in order to do the same tasks multiple times.
So the next one is The while loop.
So the javascript while loop iterate the element for the infinite number of for time it should be use
if the number of iteration is not known.
So unlike these for loop in which case that iteration should be known because you have to give the conditional
way here.
But if the number of iteration is unknown for you that means you have to make use of these y.
So while is all in lowercase and give the condition over here so it should be the condition same as
the for loop.
And after that you will thus give the court inside this scope to be executed.
So lets make use of this who I look now.
So first of all while and here let me just first grade one variable so I'll just say for I.
Easy goal.
So we call.
Let me say love and to upgrade the variable.
So let me just script the while loop and I'll just give the condition inside these separatists is so
the same say while I is laser recall 15 you have to first increment your eyes so I plus plus is same
as saying I plus 1.
So do this.
And after that you have to this console.
So the second Soledad to lug and your name.
After that you will just close this down.
So here what happens is basically let me just do this below here up to you this chord.
So what happened here.
So you can see the sorting has been printed numerous times.
So you have this forward here to put some.
That is the deadline so you could see the way pace is slowing your browser because you have the persistent
log over here.
So you have to close now
so I'll just say stop this.
So because we just didn't board that is a plus plus which was the increment.
So due to that we had the problem over there.
So let me just go to the console again and let me just dive real quick again.
So first of all it should be the variable
is just keep the code to be executed.
And after that you have to this put a plus plus away.
So which will this give some condition in order to terminate this loop otherwise it in this loop the
in finite time and it will this oh just make our browsers slower and slower and it will just break your
browser.
So if I just press into now then you see this search in has been printed for this is five times because
you have a condition over here while I easily recall 15.
That means it will this say this condition it will increase the value eleven to 211 again take the condition
and it will just print the same as such in value by here.
That is five times.
So this is another way that these alternative to the for loop.
But it has this special case that if the number for deletion is unknown for you you can make use of
the while unlike that of four.
So next one is your do while loop.
So the zombies could do I loop it it is the number for the in finite number of a time like a while loop
but Gordy's executed at least the ones whether the condition is true or false.
So if we just see over here we just made the use of this while loop.
So what if I just make use of candy and like very well I should be 20 and again around discord that
means the condition is false so what here.
And when the condition is false it only execute.
Even at the one time.
So that means if the condition is false it won't execute in the case of a while loop.
But in the case I would do well at least a one time the code will be executed and it doesn't matter
either.
The condition is true or false.
So let me just take example over here so let me script the variable.
This give the name.
Let me see I.
And let me just create this and do well and allow the same.
Do something for me so sick console me and so luck lug
and let me just close this down over here.
I have to this increment the value of i.
And after that I'll just put while and after the while you have to give the condition I'll just say
let's recall to 25 and you have to give the semicolon at the end.
It is essential.
So if you see her in the key here that is the condition or the value over here is twenty one.
So what if let's say that it is two.
So clearly the condition of it here is as follows.
Because 21 is not.
Let's recall the two even if the condition is false.
You do not execute the search in a one time.
So you do this execute this as in and you could see over here.
It did not swing the multiple time that means the setting has been printed only one time and either
of the condition that is it can be true or false.
Inside this while loop one time this line of code will be executed.
It won't matter of this condition inside these who statement.
So this is the difference between the do while and the while loop so do file will execute the chord
at least once whether the condition is true or false.
Unlike of that of while in the case of a while.
If the condition is false it only execute at least are basically you don't execute any chord but in
the case of Doyle it will execute at least one time if the condition is true or false are or whether
the condition is true or false.
So this is your for while and do a loop.
And this is really important to know about the loop.
You can make you use up the reputation of your chord based on that looping condition.
So in the next lecture you learn about the fun essence and summary in objects and will just directly
dive into some of that ones concept of a javascript and learn about the BRB suit.
So see in the next one.