In previous video, we have talked about and described how up works and now it's time to consider other
types of loops which are wild and do while while Loop does actually almost the same work as for a loop.
The main difference between them is in Syntex, as I remember.
In case of rollup, we had three statements in parentheses, initialization condition and increment
or decrement.
As for the while the counter is created outside it, then we need to write words while inside parentheses
we have only the condition.
And inside the Brice's, we have a block of code where we can put the increment or the of the counter,
so it's right, cancel that log.
I and then I plus plus reload the page and we have hear numbers from zero to 10 because in while we
had condition I is less than or equal to 10.
OK, as I see it plus plus is written after the council.
But if we place it before council then we will get the numbers from one to 11.
It seems a little bit strange.
So let me explain what has happened here, as you know, in case of a look at the value of counter was
updated after the execution of the code block.
In this case, we see that eye is set as zero.
It means that we have zero is less than or equal to that in condition.
Then JavaScript engine continues reading codes line by line.
It says E-Plus Plus and updates its value from zero to one.
And that's the reason why we got one as the first number instead of zero.
And also, that's why the result ends with 11, when it becomes 10, then the condition is true.
But because of that we have a plus plus before council log that the value of AI becomes 11 for the last
iteration.
Makes sense.
All right, this will make us unexpected results when we use while loop with a race in practice.
Let's see what I mean, create a right of colors and insert here some colors, light red than green
and blue.
And use wire look to output the items of the array, set the counter as zero that creates while.
Weather condition is less than colors that length.
And inside the coal prices.
Run in council colors, I and then I plus plus.
Without and you, we have our colors in order.
But if we place a plus plus before council, that log.
That.
You said that the first item escaped and after the last item we have identified.
The reason is, say, for the last iteration, I became four and we know that item with index number
four doesn't exist in the array and that's why we got undefined.
All right, the next that I want to show you is do I loop the do loop is like the wire loop, but it
executes the block of code once before, checking if the condition is true or false.
If it's true, then to wire loop will continue looping as long as the condition is true.
At first we write the key do.
Then inside the Culebra we need to write block of code.
Right, again, cost of log.
Caldas, I.
And then the increment I plus plus.
After that, we have to right to keep keyboard while with its condition.
Let's reload the page and again, we have colors from the air, right, as we said, in case of four
and while loops the execution of block of code would not start and execute if the conditions are false.
But in case of develop, it doesn't matter whether condition is true or false.
The first iteration will be always executed.
So if we make your condition false and right eye is greater than color length, then we will get all
of the first item from the array, which is white.
So remember that in case of the wallop, at first the code is executed and that the condition is checked,
if it's true, the loop is continuing to work accordingly before the condition becomes false.
This is the main difference between life and death.
Wallach's.
All right, so in this lecture, we have learned a while and two while loops are and how they work,
let's move on.