Hey, in this bonus example, I want to focus on the for loop.
I want to make sure you understand what the full loop does, because a full loop is something that you
will use over and over again when you create the applications.
You saw the full loop here inside this match case block But the full loop can also be outside, of course.
So let's suppose we have a list of meals.
Let's say we have pasta, pizza and salads.
So if you want to print out these in the common line.
You do for meal in meals.
Print.
Meal.
So if you run this, you get pasta, pizza and salad.
And of course, you can add methods.
Socialists capitalized to capitalize the first letter of each word.
So what's going on here is that this mail is a new variable.
This variable is created on the fly.
So in each iteration, all the backstage, what's happening is something like meal is equal to.
Pastor.
That's what happens in the first iteration.
And so pastors that capitalize is printed out by the print function.
Then in the next iteration, the variable is declared again, implicitly, we don't see it, but the
variable again is pizza.
This time pizza is capitalized and it's printed out, and that's how it works.
And if you say print boy at the end, boy will be printed out when the iteration finishes.
So we get all the items over the list printed out first and then comes by.
So the full loop behaves like the while loop.
The difference is that while loops run, as long as a condition is true and for loops run as long as
there are items in the list which is being iterated.
And you can also iterate over strings, not only over lists.
So here we are iterating over this list.
Now, if you change meals to a string, let's say like that and run, this is what you're going to get
m, e, a, l, c, And each letter is capitalized because no meals is not that variable anymore.
So that is not being used.
We can delete it so wrong again.
You get meals.
Meals.
So list and strings have this similarity.
They are treated as sequences of objects.
So the list in our case had three objects, which was pasta, pizza and salad.
Our string in this case has one, two, three, four, five objects which are strings.
So each of them is a character and you can iterate over strings.
Of course, in this case you would want to change this variable to a more meaningful name, maybe Curr
which means character or whatever you like.
So now it makes more sense.
I hope this gave you some more clarity on the full loop.
Thank you for following.