1 00:00:00,540 --> 00:00:06,090 So carrying on with conditional statements, we're going to look at the switch case statement now as 2 00:00:06,090 --> 00:00:09,450 to which case does the same functionality really as if all else. 3 00:00:09,810 --> 00:00:13,020 But it's a little bit cleaner to read and a little bit cleaner to write. 4 00:00:13,690 --> 00:00:18,630 If I just jump dump in something, it's going to take me ages to type, which is much better if I just 5 00:00:18,630 --> 00:00:19,130 dump it in. 6 00:00:19,680 --> 00:00:24,450 We have, first of all, some character, which in this case is the letter Z. 7 00:00:26,380 --> 00:00:32,060 The switch case statement starts with a switch statement where we say switch some character. 8 00:00:32,260 --> 00:00:41,080 So this is looking at the variable up here and it's saying in the case that that variable is a then 9 00:00:41,080 --> 00:00:47,050 I want you to do whatever the following lines of code are in the case that it said, do this following 10 00:00:47,050 --> 00:00:52,000 line of code in the case that it is B or why that's not. 11 00:00:52,000 --> 00:00:53,290 And that is or. 12 00:00:55,140 --> 00:00:57,430 Then it's going to be second last letter of the alphabet. 13 00:00:57,450 --> 00:00:59,820 It also should be second letter of the alphabet. 14 00:01:01,560 --> 00:01:07,500 Let's change that second, first or last letter of the alphabet, and then just like the if else, the 15 00:01:07,500 --> 00:01:09,540 P&L statement covers all eventualities. 16 00:01:09,660 --> 00:01:16,300 In this case, the default covers all the remaining eventualities, print some other character. 17 00:01:16,890 --> 00:01:19,680 So if we run that, we should get last letter of the alphabet. 18 00:01:20,460 --> 00:01:21,780 If I drop that to a B. 19 00:01:24,600 --> 00:01:26,410 We should get a MacBook. 20 00:01:26,430 --> 00:01:31,860 You got this second, last, second, first or last letter of the alphabet. 21 00:01:32,670 --> 00:01:35,170 OK, so that's the switch case in a nutshell. 22 00:01:35,340 --> 00:01:38,390 Now, the switch case has many features that we can implement. 23 00:01:38,940 --> 00:01:42,540 And I'm just going to copy over this code here, because, again, it's long and convoluted. 24 00:01:46,480 --> 00:01:49,880 So we have an approximate count of 62. 25 00:01:50,200 --> 00:01:55,060 We have counted things, moons orbiting Saturn and we have a natural count. 26 00:01:57,230 --> 00:02:03,770 Now, these three variables are going to combine with the switch case can statement to provide a human 27 00:02:03,770 --> 00:02:06,410 readable output at the end, which is this. 28 00:02:07,220 --> 00:02:11,270 And the way we're going to go about that is to look at the approximate count. 29 00:02:12,650 --> 00:02:19,940 And say if there are zero in that approximate count, then the natural count is equal to no, as in 30 00:02:20,480 --> 00:02:27,440 we're turning a number into an approximation or a natural approximation that humans understand. 31 00:02:27,830 --> 00:02:28,970 So you wouldn't say why? 32 00:02:28,970 --> 00:02:36,080 You would say there is zero moons orbiting whatever planet Pluto, but it's more likely you would say 33 00:02:36,080 --> 00:02:38,420 there are no moons orbiting Pluto. 34 00:02:40,320 --> 00:02:48,720 In the case of one or less than five, so in that range, one, two, three, four, we're going to 35 00:02:48,720 --> 00:02:49,920 have a few. 36 00:02:50,880 --> 00:02:53,550 In the case of five to 12, we're going to have several. 37 00:02:54,930 --> 00:02:58,570 Twelve to one hundred, dozens of one hundred thousand. 38 00:02:58,590 --> 00:03:04,020 Hundreds of and of course, anything else is just going to be many or an s load, if you like. 39 00:03:04,680 --> 00:03:09,300 So once we run through this, 62 will come out to dozens of. 40 00:03:11,010 --> 00:03:13,950 And it will say there are dozens of. 41 00:03:15,070 --> 00:03:20,080 Counted things, which is moons orbiting Saturn, so we hit play on that. 42 00:03:21,890 --> 00:03:28,490 There are dozens of moons orbiting Saturn, so this is an example of a more expansive switch case statement 43 00:03:28,670 --> 00:03:30,740 where we're actually taking ranges into account. 44 00:03:31,160 --> 00:03:35,720 Now, there are many other things we can do, switch cases, we can assign variables and things like 45 00:03:35,720 --> 00:03:35,960 that. 46 00:03:36,230 --> 00:03:40,330 But we're not going to do that here because you don't actually need it that often. 47 00:03:40,340 --> 00:03:43,160 In my experience, it comes a time if you do need it. 48 00:03:44,480 --> 00:03:45,650 OK, do I have homework? 49 00:03:45,890 --> 00:03:46,880 Oh, yes. 50 00:03:50,170 --> 00:03:51,040 Here it is. 51 00:03:52,470 --> 00:03:58,140 Create a switch statement to call someone young, middle aged or old, so we did this in the previous 52 00:03:58,140 --> 00:04:02,910 lesson with the if else, but now you can do it with a switch case.