Welcome back.
Before we go to the follow-up, I wanted to show you another application of the while loop because it
will make it a little more clear what the differences and when to use what.
So, for example, the for loop is really there to iterate through ranges, arrays and so forth, and
we will see what that means in the next video.
But before we do so, we will have to look at while loops which are great to execute a block of called
repeatedly as long as the condition is met, as we saw earlier.
So let's have an example where we don't look at numbers because so far we only looked at numbers.
We said, OK, var x.
As long as this white, then do something.
But now let's say we have the situation where we have a variable called felt temperature and that one
will be called.
So let's say we are in the room and it feels like it's cold.
So we don't know directly what temperature it is in terms of degrees, right, in terms of degrees Celsius.
So we have also a value called room temperature, which actually is that value.
So let's say 10 degrees.
And.
Now we will run a wild loop, which will increase the temperature, the room temperature by one degree
until it's warm enough, so that felt temperature is not cold anymore.
So here we are, just going to say as long as felts temp is cold, please run this wire loop, which
will, as I said, increase the room temperature.
So now, of course, we still need a situation where this condition is not met anymore, so we need
to create this situation so we can check if the room temperature is greater or equal.
20.
Then set a felt temperature, too comfy, so too comfortable, so it's not going to be cold anymore.
And also print something onto the console, parental and.
It's comfy now.
So now if we execute this.
It will just print its comfy now.
Why is that what happened in this whole thing?
Well, we set the felt temperature too cold because when it's 10 degrees Celsius, then it's pretty
cold and you don't want to be in the room when it's that cold.
You want it to be 20 degrees Celsius.
Which is sixty eight degrees Fahrenheit.
All right, so what you say is as long as it's called, please turn up the heat, so increase the room
temperature by one.
And as soon as the room temperature hits 20 degrees.
Then set the false temperature too comfy.
So now in the room, we feel like all right is comfy, it's a good temperature.
We can maybe even get rid of our jacket and then we can print.
It's comfy now.
And our while loop will stop, so at that point, our while loop will not increase the room temperature
anymore and it will jump out of this whole loop and execute whatever comes afterwards.
So this is just another application where you see that it doesn't have to be an integer that we're checking
here.
It can be whatever condition that has to be met.
And as soon as this condition is not only met anymore, the while loop will stop executing its block
here, its body, it's called block.