We introduce the wildy last time which is really the only loop we need.
But today I want to go over a slight variation of the while loop and it's called the do while loop.
So here's how you write a do while loop.
So you have to do which is a key word and you have the statement blanks on your statements here and
you have the while condition actually at the end not the beginning like the while.
And you have a semi-colon.
So this is very important.
Don't forget the semi-colon otherwise it will complain.
So this really is like an inverted Waialua And no you you do need the semi-colon unlike B the regular
white loop.
You didn't there was no semi-colon before so you may ask what the differences between a while loop and
a do while loop and it's really when the condition is checked.
So a while loop will check the condition first before anything happens.
And the do while loop will check the condition after the first iteration has completed so it will actually
go and say Do you really just doesn't do anything actually.
And it was sort of passed through there and actually just start doing all of the statements in the do
while loop and then at the after the last statement then it will check the condition.
So again this is very much like the exact opposite of the while loop or inverted while loop.
So it's kind of see the difference in action.
So let's just actually get rid of this and say it goes to one and conc in smacks
goes to zero and we're going to say while it is less than or equal to Max
in printout so in the wild
This K and then we're going to write a do while as well and say the same condition.
The semi-colon very important for the do while loop.
And we're going to s.c out
the two while
are going to write this and this.
That's all it printed out is in the do while loop.
So somehow I had Max to be zero and 1 is not less than or equal to max so it checked the condition for
this while loop first.
Like I said and this evaluates to false of course.
Right.
So it didn't do any iterations of this while but it did do it one iteration of the do while loop.
So that's really the difference between the two the do while loop will always check the condition last
and the while loop will and will check the condition first.
That's really the main difference.
And you may be asking why would you want such a loop.
Why.
Why even have this.
Well I'll be showing you an example of why you'd want to use this in one of our upcoming lectures.
They'll have to do with input in fact.
So next time going to go over last looping structure called the form.