WEBVTT

00:00.600 --> 00:04.940
So one thing you can do with loops is nest them.

00:05.000 --> 00:08.000
So let's see an example of what I mean.

00:08.000 --> 00:13.790
So let's say we have contest in Max goes to five

00:16.520 --> 00:19.360
and we say.

00:19.820 --> 00:28.240
He calls to 1 is less than or equal to Max an.

00:28.610 --> 00:29.660
Plus plus

00:32.490 --> 00:34.700
and then we say zero out

00:39.520 --> 00:42.220
interation is

00:45.180 --> 00:45.660
I

00:52.460 --> 00:57.920
and then we say 4 inch J goes to 1.

00:57.950 --> 01:00.520
So we're not using or using j.

01:00.640 --> 01:11.270
Because I I could be used inside of this in J 4 but we don't want that to happen so we have to use a

01:11.270 --> 01:14.270
different variable here.

01:14.860 --> 01:26.110
Less than or equal to max Juniperus us and same thing iteration J.

01:27.610 --> 01:30.130
Is just

01:33.060 --> 01:37.660
and run this and see what it outputs.

01:37.710 --> 01:40.940
So you see Aerschot I is equal to 1.

01:41.220 --> 01:57.490
And then you say that he see iteration J from 1 to 5 K so it only did 1 iteration I 4 5 iteration James

01:59.060 --> 02:02.780
or 5 iteration js for one iteration.

02:03.380 --> 02:04.600
That makes sense.

02:05.060 --> 02:16.280
And then so see here iteration equals 2 and we do iteration J 2 from 1 to 5.

02:16.320 --> 02:22.050
And the same thing with three went to 5 for J eyes for 1 to 5.

02:22.110 --> 02:23.030
J.

02:23.320 --> 02:28.340
Narration 5 in 1 to 5 for J.

02:28.350 --> 02:35.470
So you see we do five iterations of J for each iteration of I.

02:35.550 --> 02:39.270
So you may ask why is this useful.

02:39.270 --> 02:45.340
Well we'll see later for much harder problems.

02:45.870 --> 02:54.300
Having multiple loops really does help and really solves some much more interesting problems than just

02:54.360 --> 03:03.740
having sort of a linear non nested loop and I'll show you some examples of that in the practice problems.

03:03.750 --> 03:05.070
Lecture this section.
