WEBVTT

00:00.530 --> 00:06.460
We introduce the wildy last time which is really the only loop we need.

00:06.620 --> 00:13.510
But today I want to go over a slight variation of the while loop and it's called the do while loop.

00:13.700 --> 00:17.520
So here's how you write a do while loop.

00:17.660 --> 00:28.100
So you have to do which is a key word and you have the statement blanks on your statements here and

00:28.100 --> 00:34.670
you have the while condition actually at the end not the beginning like the while.

00:36.630 --> 00:40.170
And you have a semi-colon.

00:40.170 --> 00:41.840
So this is very important.

00:41.880 --> 00:46.350
Don't forget the semi-colon otherwise it will complain.

00:47.050 --> 00:59.050
So this really is like an inverted Waialua And no you you do need the semi-colon unlike B the regular

00:59.140 --> 00:59.720
white loop.

00:59.740 --> 01:08.620
You didn't there was no semi-colon before so you may ask what the differences between a while loop and

01:08.620 --> 01:14.520
a do while loop and it's really when the condition is checked.

01:14.580 --> 01:21.860
So a while loop will check the condition first before anything happens.

01:22.140 --> 01:30.300
And the do while loop will check the condition after the first iteration has completed so it will actually

01:30.300 --> 01:35.400
go and say Do you really just doesn't do anything actually.

01:35.640 --> 01:42.960
And it was sort of passed through there and actually just start doing all of the statements in the do

01:43.030 --> 01:50.840
while loop and then at the after the last statement then it will check the condition.

01:50.900 --> 01:59.180
So again this is very much like the exact opposite of the while loop or inverted while loop.

01:59.260 --> 02:03.230
So it's kind of see the difference in action.

02:03.230 --> 02:13.990
So let's just actually get rid of this and say it goes to one and conc in smacks

02:16.690 --> 02:24.970
goes to zero and we're going to say while it is less than or equal to Max

02:27.590 --> 02:33.810
in printout so in the wild

02:38.510 --> 02:50.200
This K and then we're going to write a do while as well and say the same condition.

02:53.670 --> 02:57.830
The semi-colon very important for the do while loop.

02:57.910 --> 03:00.420
And we're going to s.c out

03:02.990 --> 03:04.460
the two while

03:10.500 --> 03:13.690
are going to write this and this.

03:13.700 --> 03:20.360
That's all it printed out is in the do while loop.

03:20.350 --> 03:30.680
So somehow I had Max to be zero and 1 is not less than or equal to max so it checked the condition for

03:30.680 --> 03:32.570
this while loop first.

03:32.600 --> 03:38.230
Like I said and this evaluates to false of course.

03:38.230 --> 03:39.010
Right.

03:39.170 --> 03:49.460
So it didn't do any iterations of this while but it did do it one iteration of the do while loop.

03:49.760 --> 03:57.080
So that's really the difference between the two the do while loop will always check the condition last

03:57.470 --> 04:01.520
and the while loop will and will check the condition first.

04:01.520 --> 04:03.340
That's really the main difference.

04:03.380 --> 04:07.650
And you may be asking why would you want such a loop.

04:07.660 --> 04:08.330
Why.

04:08.460 --> 04:09.970
Why even have this.

04:10.220 --> 04:18.440
Well I'll be showing you an example of why you'd want to use this in one of our upcoming lectures.

04:18.460 --> 04:20.870
They'll have to do with input in fact.

04:21.110 --> 04:27.210
So next time going to go over last looping structure called the form.
