Hey, welcome to the Discord experiment.
In this video, we're going to run two experiments on the match case block and one experiment on the
for loop.
Let's first start with the first experiment.
All the match case block.
So when we run this program as a user, we are expected to enter either add, show or exit.
But what happens if we enter something else, like a random piece of text?
If you press enter, the program will ask you again to type in add, show or exit.
So my question to you here is what happens after we entered this random string?
Which of these code blocks was executed?
The one under ads.
The one on the show or the one on the exit?
The answer is none of them was executed.
What happened is that all these lines were ignored because the case was not matched and therefore the
loop went again back to.
The first line.
So the wild loop was executed again.
And that's why we get this text printed out.
So that is the result of this line being executed.
Now, what if we wanted to show something, some other text when the user enters some text which doesn't
match any of these cases?
Well, in that case, you should add another case.
Here.
And instead of matching the random string, you want to place a variable such as X or whatever.
It just has to be a variable and you don't need to define it anywhere in the code.
So this variable will be defined on the fly.
So you see Case X or whatever variable.
And under this perhaps you want to print a message such as Hey, you enter an unknown command.
So if I try the script now run and I enter a random string again, press enter.
This time we get this printed out.
So as you can see, this time this code was executed because the case was matched with that anonymous
variable as a conventional view.
Instead of using whatever variable name here, it's good to use just an underscore.
So this name is like a convention to have among programmers so that you know what you mean when you
have this code.
So it's good to use that underscore even though you don't have to.
And so that was the first experiment.
So this is what you can do if you want to execute some lines when none of the cases is matched.
We're not going to implement this in the program.
So I'm going to delete that.
It was just to show you that that is also possible.
And the second experiment is.
Let's go to case show and make a space, then type in.
A vertical bar symbol on your keyboard.
You can type this in using alt seven or shift backslash.
Perhaps it depends on your keyboard.
Or maybe you can find this on Google and copy and paste it in your ID, and after this I'll write another
string display.
If I run this code and I add a to do so, I press on, add press and clean press enter.
And then instead of show, I can also write this play here.
And if I press enter, I'll get a list of to items.
So this is a bitwise or operator.
So this will match either show or display.
So if one of these strings is matched, then this is evaluated to true.
So these lines will be executed.
All right.
That was the second experiment.
Let me delete that as well.
If you want, you can keep it.
But I don't want to have lots of code here.
I don't want to add any possible feature to this program because that will make my code complex.
And that means it can be hard for you to see what I'm typing in and what time explaining.
So it's better to keep the program simple but functional so that you understand the new concepts.
The third experiment I want to focus on for Loop this time, and I just want to make sure that you know
that you can add more lines under the for loop line.
So under the first line, for example, you can say item is equal to item dot title.
So we get the two items, each item, each string to do list, and we convert the characters, the first
characters of those words into title case, and then we print out the results.
So we reassign this variable.
Let's see what this will bring us.
So run and clean the bag at Throw the trash.
Press enter show Now Show will display the to the items with the first letter of each word capitalized.
So see is capitalized t as well and so on.
And that is made possible by this title method.
So my point with this experiment is that under this line you can have as many lines as you want, but
be aware that they should be all indented in the same indentation level.
So that means four spaces for each of these lines under the fourth line.
And that was the last experiment.
So I hope this gives you some more understanding of the match case.
BLOCK And the for loop.
I'm glad to still have you in the course.
So let's keep going.
See?