1
00:00:01,040 --> 00:00:05,320
Hey, in this bonus example, I want to focus on the for loop.

2
00:00:05,330 --> 00:00:11,260
I want to make sure you understand what the full loop does, because a full loop is something that you

3
00:00:11,260 --> 00:00:15,200
will use over and over again when you create the applications.

4
00:00:16,300 --> 00:00:25,570
You saw the full loop here inside this match case block But the full loop can also be outside, of course.

5
00:00:27,400 --> 00:00:32,710
So let's suppose we have a list of meals.

6
00:00:40,380 --> 00:00:45,360
Let's say we have pasta, pizza and salads.

7
00:00:47,070 --> 00:00:50,310
So if you want to print out these in the common line.

8
00:00:51,960 --> 00:00:54,900
You do for meal in meals.

9
00:00:56,490 --> 00:00:57,210
Print.

10
00:00:59,200 --> 00:00:59,860
Meal.

11
00:01:01,250 --> 00:01:05,570
So if you run this, you get pasta, pizza and salad.

12
00:01:06,390 --> 00:01:08,400
And of course, you can add methods.

13
00:01:11,700 --> 00:01:15,960
Socialists capitalized to capitalize the first letter of each word.

14
00:01:16,110 --> 00:01:21,600
So what's going on here is that this mail is a new variable.

15
00:01:21,720 --> 00:01:24,810
This variable is created on the fly.

16
00:01:25,620 --> 00:01:33,840
So in each iteration, all the backstage, what's happening is something like meal is equal to.

17
00:01:35,770 --> 00:01:36,400
Pastor.

18
00:01:36,520 --> 00:01:40,000
That's what happens in the first iteration.

19
00:01:40,000 --> 00:01:44,440
And so pastors that capitalize is printed out by the print function.

20
00:01:44,560 --> 00:01:51,580
Then in the next iteration, the variable is declared again, implicitly, we don't see it, but the

21
00:01:51,580 --> 00:01:53,190
variable again is pizza.

22
00:01:53,200 --> 00:01:57,970
This time pizza is capitalized and it's printed out, and that's how it works.

23
00:01:59,920 --> 00:02:11,890
And if you say print boy at the end, boy will be printed out when the iteration finishes.

24
00:02:11,890 --> 00:02:18,430
So we get all the items over the list printed out first and then comes by.

25
00:02:18,430 --> 00:02:22,510
So the full loop behaves like the while loop.

26
00:02:23,260 --> 00:02:32,440
The difference is that while loops run, as long as a condition is true and for loops run as long as

27
00:02:32,440 --> 00:02:37,180
there are items in the list which is being iterated.

28
00:02:37,660 --> 00:02:44,220
And you can also iterate over strings, not only over lists.

29
00:02:44,230 --> 00:02:47,650
So here we are iterating over this list.

30
00:02:47,890 --> 00:02:58,750
Now, if you change meals to a string, let's say like that and run, this is what you're going to get

31
00:02:59,560 --> 00:03:09,190
m, e, a, l, c, And each letter is capitalized because no meals is not that variable anymore.

32
00:03:10,190 --> 00:03:11,680
So that is not being used.

33
00:03:11,690 --> 00:03:14,780
We can delete it so wrong again.

34
00:03:15,110 --> 00:03:16,460
You get meals.

35
00:03:16,980 --> 00:03:18,300
Meals.

36
00:03:19,310 --> 00:03:22,970
So list and strings have this similarity.

37
00:03:22,970 --> 00:03:27,710
They are treated as sequences of objects.

38
00:03:27,890 --> 00:03:34,250
So the list in our case had three objects, which was pasta, pizza and salad.

39
00:03:34,340 --> 00:03:42,410
Our string in this case has one, two, three, four, five objects which are strings.

40
00:03:42,410 --> 00:03:47,390
So each of them is a character and you can iterate over strings.

41
00:03:48,290 --> 00:03:54,860
Of course, in this case you would want to change this variable to a more meaningful name, maybe Curr

42
00:03:54,920 --> 00:03:58,250
which means character or whatever you like.

43
00:03:59,030 --> 00:04:00,830
So now it makes more sense.

44
00:04:02,340 --> 00:04:05,850
I hope this gave you some more clarity on the full loop.

45
00:04:06,060 --> 00:04:07,260
Thank you for following.

