WEBVTT 00:00.760 --> 00:05.890 Welcome in its catting lecture, I'm going to show you a comparison between an IF statement and a switch 00:05.890 --> 00:09.100 statement, so you'll clearly see which one to use and one. 00:11.280 --> 00:12.010 Let's take a look. 00:18.640 --> 00:23.890 In this program, I'm going to get a man's name from the common line, then I will print the season. 00:25.560 --> 00:31.320 Let's first check that there are enough arguments, I'm expecting only one argument, so I'm going to 00:31.320 --> 00:35.220 check for that like this if LAN is ARC's. 00:36.470 --> 00:37.760 Not equal to two. 00:43.770 --> 00:47.040 You've seen this a lot of times before, so I'm not going to explain it again. 00:47.940 --> 00:48.530 All right. 00:48.540 --> 00:51.690 Now let's assign the moms into the embeddable. 00:53.350 --> 00:57.250 Umm, short declare that ARC's want. 00:58.210 --> 01:05.950 OK, first, I'm going to check for the winter months, if is December or January. 01:07.410 --> 01:08.610 Our February. 01:10.080 --> 01:12.510 OK, then I'm going to print winter. 01:13.860 --> 01:15.200 Prednisolone winter. 01:15.450 --> 01:15.830 OK. 01:16.980 --> 01:22.200 If demand is no interments, then let's check for Sprink bonds this time. 01:23.270 --> 01:26.490 I'll see if I'm equals to March. 01:27.580 --> 01:28.980 Or April. 01:30.220 --> 01:31.390 Or May. 01:32.200 --> 01:34.990 OK, now I'm going to print Sprink. 01:37.600 --> 01:38.050 OK. 01:39.340 --> 01:43.900 If the Mount is in a shopping mall mount either, then let's check for the summer months since that. 01:45.340 --> 01:50.550 If, um, equals to June or July. 01:52.820 --> 01:53.960 Our August. 01:56.670 --> 01:58.950 OK, now I'm going to print summer. 02:01.930 --> 02:05.800 OK, and lastly, let's check for the full moms'. 02:07.130 --> 02:09.950 Passive equals to September. 02:11.120 --> 02:15.350 Or October or November. 02:18.000 --> 02:18.570 OK, the. 02:19.610 --> 02:20.720 Then I'm going to print for. 02:23.020 --> 02:25.760 OK, let's put on our branch here. 02:26.320 --> 02:31.810 So if the user provides the wrong mom's name, I'm going to let the user know that it's a wrong mom 02:31.850 --> 02:32.080 name. 02:33.730 --> 02:40.680 F.A. printf person Q is not a mom's new line now I'm going to pass. 02:41.560 --> 02:43.510 OK, this is a good behavior. 02:43.780 --> 02:46.960 You should always display meaningful error messages like this. 02:47.650 --> 02:47.950 OK. 02:48.050 --> 02:49.540 OK, now let's try it. 02:50.900 --> 02:53.120 First, let's call it directly with Antimonopoly. 02:54.120 --> 02:57.240 It's brain implant, it detects that good. 02:58.320 --> 03:01.920 Now, let's give it a winter months like this February. 03:02.870 --> 03:04.860 Great, it says it's a winter months. 03:05.630 --> 03:08.770 Now, let's give it a spring bounce, April. 03:09.930 --> 03:15.870 Cool, now it says it's a spring once and lastly, let's try it with a wrong name like this. 03:19.530 --> 03:21.300 Good, it displays their message. 03:22.350 --> 03:24.560 OK, this car looks messy, right? 03:26.170 --> 03:32.800 I don't know about you, but it's hard to read, at least for me now let me show you, how can I transform 03:32.800 --> 03:34.210 this into a switch statement? 03:35.080 --> 03:36.430 This will make it more readable. 03:37.210 --> 03:42.490 Actually, the whole point of a switch statement in go is to make longer if statements more readable. 03:43.700 --> 03:45.560 OK, now I'm going to type a short switch. 03:47.200 --> 03:49.390 I'm going to declare the Amber Abel here first. 03:50.330 --> 03:53.520 Then as its condition, I'm going to type the amber variable here. 03:54.380 --> 03:54.920 All right. 03:56.060 --> 03:58.460 Now, I'm going to duplicate these statements here. 03:59.930 --> 04:02.540 I'm going to remove it right inside the switch statement. 04:06.120 --> 04:09.570 Now, I'm going to select all the comparisons with Kamandi. 04:12.680 --> 04:18.710 I don't need to let's remove the good going to select all the logical operators. 04:20.490 --> 04:22.710 Let's convert them to commerce instead. 04:24.190 --> 04:27.760 OK, good novelists select this as if branch's. 04:29.540 --> 04:31.520 That's Makhdoom case Claus's instead. 04:34.090 --> 04:37.360 This also changed this if here to a case class. 04:40.860 --> 04:43.980 And this convert is our branch to our default case. 04:48.670 --> 04:52.000 Now, let's convert is opening curly braces to Cullum's. 04:54.300 --> 04:56.880 And lastly, let's remove the closing prices. 05:02.840 --> 05:03.590 All right, Don. 05:04.680 --> 05:05.500 That's right. 05:06.090 --> 05:11.340 Let's run it a few times with different bombs go around mean that go February. 05:14.770 --> 05:15.610 With April. 05:16.670 --> 05:19.760 With June, with November. 05:21.140 --> 05:22.430 Killed Celiac's. 05:23.710 --> 05:26.620 And lastly, let's try it with a dummy mom's name again. 05:27.740 --> 05:28.820 OK, it works. 05:30.070 --> 05:33.310 Now, let's compare this switch to the if statement about. 05:35.750 --> 05:41.990 I see a huge difference, this is what I was trying to tell you, so when you have an unreadable if 05:41.990 --> 05:46.880 statement like this, try to change it into a switch statement instead. 05:47.980 --> 05:50.170 Now, let's remove the if statement for good. 05:53.690 --> 05:54.920 Right, that's all for now. 05:55.690 --> 05:56.680 Thank you for watching. 05:56.770 --> 05:58.420 See in the next picture by.