1
00:00:01,560 --> 00:00:04,260
Hey, welcome to the Discord experiment.

2
00:00:04,800 --> 00:00:11,270
In this video, we're going to run two experiments on the match case block and one experiment on the

3
00:00:11,280 --> 00:00:12,510
for loop.

4
00:00:13,320 --> 00:00:15,630
Let's first start with the first experiment.

5
00:00:15,630 --> 00:00:17,490
All the match case block.

6
00:00:18,460 --> 00:00:26,720
So when we run this program as a user, we are expected to enter either add, show or exit.

7
00:00:26,740 --> 00:00:31,960
But what happens if we enter something else, like a random piece of text?

8
00:00:32,229 --> 00:00:39,580
If you press enter, the program will ask you again to type in add, show or exit.

9
00:00:40,840 --> 00:00:47,230
So my question to you here is what happens after we entered this random string?

10
00:00:47,980 --> 00:00:51,160
Which of these code blocks was executed?

11
00:00:51,190 --> 00:00:53,110
The one under ads.

12
00:00:53,140 --> 00:00:57,580
The one on the show or the one on the exit?

13
00:00:58,330 --> 00:01:02,260
The answer is none of them was executed.

14
00:01:02,950 --> 00:01:12,070
What happened is that all these lines were ignored because the case was not matched and therefore the

15
00:01:12,070 --> 00:01:14,230
loop went again back to.

16
00:01:15,030 --> 00:01:16,410
The first line.

17
00:01:16,410 --> 00:01:19,800
So the wild loop was executed again.

18
00:01:21,350 --> 00:01:24,890
And that's why we get this text printed out.

19
00:01:24,890 --> 00:01:28,190
So that is the result of this line being executed.

20
00:01:28,340 --> 00:01:35,930
Now, what if we wanted to show something, some other text when the user enters some text which doesn't

21
00:01:35,930 --> 00:01:38,510
match any of these cases?

22
00:01:39,050 --> 00:01:42,530
Well, in that case, you should add another case.

23
00:01:43,790 --> 00:01:44,480
Here.

24
00:01:44,780 --> 00:01:54,320
And instead of matching the random string, you want to place a variable such as X or whatever.

25
00:01:55,580 --> 00:02:00,880
It just has to be a variable and you don't need to define it anywhere in the code.

26
00:02:00,890 --> 00:02:04,670
So this variable will be defined on the fly.

27
00:02:07,160 --> 00:02:11,060
So you see Case X or whatever variable.

28
00:02:11,060 --> 00:02:21,890
And under this perhaps you want to print a message such as Hey, you enter an unknown command.

29
00:02:23,770 --> 00:02:32,350
So if I try the script now run and I enter a random string again, press enter.

30
00:02:32,380 --> 00:02:35,660
This time we get this printed out.

31
00:02:35,680 --> 00:02:44,200
So as you can see, this time this code was executed because the case was matched with that anonymous

32
00:02:44,200 --> 00:02:46,810
variable as a conventional view.

33
00:02:46,810 --> 00:02:52,450
Instead of using whatever variable name here, it's good to use just an underscore.

34
00:02:52,900 --> 00:02:58,990
So this name is like a convention to have among programmers so that you know what you mean when you

35
00:02:58,990 --> 00:02:59,980
have this code.

36
00:02:59,980 --> 00:03:03,970
So it's good to use that underscore even though you don't have to.

37
00:03:04,420 --> 00:03:06,040
And so that was the first experiment.

38
00:03:06,040 --> 00:03:14,920
So this is what you can do if you want to execute some lines when none of the cases is matched.

39
00:03:15,130 --> 00:03:17,350
We're not going to implement this in the program.

40
00:03:17,350 --> 00:03:18,910
So I'm going to delete that.

41
00:03:19,570 --> 00:03:22,780
It was just to show you that that is also possible.

42
00:03:23,080 --> 00:03:25,870
And the second experiment is.

43
00:03:26,810 --> 00:03:33,410
Let's go to case show and make a space, then type in.

44
00:03:34,230 --> 00:03:37,800
A vertical bar symbol on your keyboard.

45
00:03:37,800 --> 00:03:43,770
You can type this in using alt seven or shift backslash.

46
00:03:43,980 --> 00:03:46,340
Perhaps it depends on your keyboard.

47
00:03:46,350 --> 00:03:53,850
Or maybe you can find this on Google and copy and paste it in your ID, and after this I'll write another

48
00:03:53,850 --> 00:03:56,280
string display.

49
00:03:58,540 --> 00:04:07,990
If I run this code and I add a to do so, I press on, add press and clean press enter.

50
00:04:08,020 --> 00:04:12,490
And then instead of show, I can also write this play here.

51
00:04:13,510 --> 00:04:18,279
And if I press enter, I'll get a list of to items.

52
00:04:18,970 --> 00:04:24,640
So this is a bitwise or operator.

53
00:04:25,840 --> 00:04:29,620
So this will match either show or display.

54
00:04:29,770 --> 00:04:35,740
So if one of these strings is matched, then this is evaluated to true.

55
00:04:35,770 --> 00:04:38,110
So these lines will be executed.

56
00:04:38,950 --> 00:04:39,190
All right.

57
00:04:39,190 --> 00:04:40,870
That was the second experiment.

58
00:04:41,850 --> 00:04:43,440
Let me delete that as well.

59
00:04:44,010 --> 00:04:45,690
If you want, you can keep it.

60
00:04:45,990 --> 00:04:50,370
But I don't want to have lots of code here.

61
00:04:50,490 --> 00:04:57,510
I don't want to add any possible feature to this program because that will make my code complex.

62
00:04:57,510 --> 00:05:04,290
And that means it can be hard for you to see what I'm typing in and what time explaining.

63
00:05:04,290 --> 00:05:11,370
So it's better to keep the program simple but functional so that you understand the new concepts.

64
00:05:11,400 --> 00:05:18,270
The third experiment I want to focus on for Loop this time, and I just want to make sure that you know

65
00:05:18,270 --> 00:05:23,700
that you can add more lines under the for loop line.

66
00:05:23,700 --> 00:05:30,660
So under the first line, for example, you can say item is equal to item dot title.

67
00:05:30,930 --> 00:05:41,430
So we get the two items, each item, each string to do list, and we convert the characters, the first

68
00:05:41,430 --> 00:05:46,300
characters of those words into title case, and then we print out the results.

69
00:05:46,320 --> 00:05:48,590
So we reassign this variable.

70
00:05:48,600 --> 00:05:51,000
Let's see what this will bring us.

71
00:05:51,420 --> 00:05:59,370
So run and clean the bag at Throw the trash.

72
00:05:59,610 --> 00:06:08,160
Press enter show Now Show will display the to the items with the first letter of each word capitalized.

73
00:06:08,160 --> 00:06:11,220
So see is capitalized t as well and so on.

74
00:06:11,850 --> 00:06:14,960
And that is made possible by this title method.

75
00:06:14,970 --> 00:06:22,830
So my point with this experiment is that under this line you can have as many lines as you want, but

76
00:06:23,040 --> 00:06:28,440
be aware that they should be all indented in the same indentation level.

77
00:06:28,440 --> 00:06:33,630
So that means four spaces for each of these lines under the fourth line.

78
00:06:33,810 --> 00:06:35,310
And that was the last experiment.

79
00:06:35,310 --> 00:06:40,260
So I hope this gives you some more understanding of the match case.

80
00:06:40,260 --> 00:06:41,890
BLOCK And the for loop.

81
00:06:41,910 --> 00:06:43,830
I'm glad to still have you in the course.

82
00:06:43,830 --> 00:06:44,790
So let's keep going.

83
00:06:44,820 --> 00:06:45,040
See?

