So will come again.
This lesson is going to be a very simple lesson we are talking about two other types of control flaws
which are while loops and do while loops very similar to four loops except that they hold different
you know format for writing.
So let's jump into Axford and see how they work.
When I come in here and close this project and make it myself.
Why project the wild project here is how we do a why do why imagine I have let get my or my thing done
as usual.
Imagine I have this I have an integer that in theory is called My integer ideas Krenzel is evil and
I'm going to say why and me a complete so we can see why while condition.
My end is still below 20.
Let's do something that's the a statement let's say a synagogue All right.
Now the value for the eye.
Now this application you fire on it.
It's what's the error that you have.
Oh so it is called My hands my right arm on this application is going to do is going to run this indefinitely
because it says My answer is zero.
While my answer is below 20 keep doing this sort of while block.
We have to actually write something that changes our our expression.
So I'm going to say while that is true save my decrement.
So keep subtracting from it or actually increment.
Or in this case.
So keep going up.
So it goes 0 1 2 3 4 as long as it is below 20.
It will run this let's see that.
And once my project actually compiles builds and runs we should be able to see something in here that
says yes it is 1 2 3 4 all the way to 20 and then it stops.
Now if you are wondering why 20 isn't it true that it's because when it is 19 19 is a smaller than 20.
So this will run.
So my ins becomes 19 plus plus becomes 20.
It prints it.
And then this whole thing finishes.
If you don't want to fall in that you know pitfall essentially you can do this.
You can actually put your incrementation at the end of the while.
So now we will see that it goes from zero to 19.
So that is a wild while loop for us chicks for your expression and then runs your statement.
There is another type in here that is called Dubai.
So I'm going to say do see if it completes it for me.
It doesn't unfortunately.
So I'm going to say do I here's what I want to do.
I want to say and this long this print again or my INS should have written it properly here might in
my end is a percentage or for my of course.
And then this is essentially going to just keep doing what I'm going to do is I'm going to say why.
And then I'm going to give it a condition I'm going to say do Y.
And what's the condition of they want to use.
I want to say Do this for as long as my end is still larger than zero.
So remember my intro was zero.
We push it up all the way to 20.
Now in the do I'm going to say printed and decrement it.
Now my the.
And the difference between a vial and a do one is in the word.
You first check and then you do something in the do what you first do something and then check to see
if that was the case.
So let's run both of these
so to better illustrate that and of course this printed the way you expected it went from zero to 19
and then went from 20 to one let's say after this piece of art in here for a while.
I said it's my aunt to be let's say minus five.
See the condition is it has to be larger than zero and minus five is not.
So let's run.
So you see it runs at least once because the do part doesn't know about the condition it says well let's
do this.
What am I going to do.
And it's like my ears what's my mind says minus five.
Great.
And now let's subtract from it it becomes minus 6 and continue doing as long as I am larger than zero
and says Oh I shouldn't be continuing this anymore because already I have I have crossed the cross the
condition essentially.
So very simple.
Once again Weinman does something for you as long as this condition is true adn do while does it runs
and then checks for the condition just continues.
If you were to write any of these with a follow essentially it would be something like this it would
be for in my say is zero.
A smaller than 20 plus plus and then it would write the body for a quote in here and then incrementation
was happening within the body of the within the condition of the for loop.
I should mention that we will see this sometime in the future that we don't often use wine or two while
for situations where a for loop can be used Bijlee use it for situations when we are iterating or enumerating
in an array or in a dictionary site where we really have to use a while loop because changing incrementing
values is not within our control.
Maybe you're going to read a dictionary and we're just going to the next item in the dictionary and
we don't know how many items are there.
So if we see this sometime in the future.
For now we can almost get away for everything with with a for loop but are just preface this really
quickly.
So you know there is something called the Royland do wine and we'll come back to this at some point
down the track.
All right so let's move to.