1 00:00:05,860 --> 00:00:13,360 We can use if statements as a shorter way to write the equivalent of a match that only matches one case 2 00:00:13,870 --> 00:00:20,590 optionally if it can have an alt containing code to run if the pattern and the if left does not match. 3 00:00:20,590 --> 00:00:30,520 So as super simple example will say let dog two is equal to some pet that is a dog. 4 00:00:31,450 --> 00:00:36,220 And then if let some pet. 5 00:00:37,830 --> 00:00:41,430 That is a dog equals dog too. 6 00:00:41,940 --> 00:00:48,780 We will print out the animal is a dog. 7 00:00:49,500 --> 00:00:51,300 But if it's not a dog. 8 00:00:53,380 --> 00:00:54,700 Then we'll print out. 9 00:00:55,810 --> 00:00:56,770 Not a dog. 10 00:00:59,420 --> 00:01:01,180 So what's going on in here? 11 00:01:01,190 --> 00:01:05,720 So we're basically saying, hey, if some. 12 00:01:06,660 --> 00:01:07,800 Pet is a dog. 13 00:01:08,840 --> 00:01:09,140 Right. 14 00:01:09,140 --> 00:01:11,090 So this is the type we're looking for. 15 00:01:11,090 --> 00:01:14,330 And then we created a dog to the same type. 16 00:01:15,400 --> 00:01:18,410 So if it matches, print out the animal is a dog. 17 00:01:18,430 --> 00:01:19,930 Otherwise it's not a dog. 18 00:01:19,960 --> 00:01:23,290 So we know that this is going to print out the animal is a dog. 19 00:01:23,410 --> 00:01:26,380 But if we happen to make it a cat. 20 00:01:27,530 --> 00:01:34,390 Well, then we would expect the match up here to not match and we would expect it to print, not a dog, 21 00:01:34,400 --> 00:01:36,260 which is what happens. 22 00:01:36,410 --> 00:01:37,070 So. 23 00:01:37,900 --> 00:01:42,940 You can also extend this with elseif and elseif statements. 24 00:01:43,390 --> 00:01:49,120 So it all works the same as if we were just doing regular control flow statements. 25 00:01:49,480 --> 00:01:57,550 So we can also extend this or we can also use while loops. 26 00:01:57,550 --> 00:02:04,210 So let's create a stack and we'll call it a new vector. 27 00:02:05,500 --> 00:02:11,080 And then what we'll do is we'll put in a couple of values. 28 00:02:17,920 --> 00:02:25,090 They will change these two different numbers and now we'll execute a while. 29 00:02:25,090 --> 00:02:33,010 Let some top equals stack dot pop. 30 00:02:36,330 --> 00:02:37,320 Print out. 31 00:02:42,330 --> 00:02:42,990 Top. 32 00:02:44,040 --> 00:02:45,330 So what's going on here? 33 00:02:45,330 --> 00:02:50,280 So we created a new vector, pushed in three values of one, two and three. 34 00:02:50,280 --> 00:02:53,730 And then we're saying, Hey, pop the stack. 35 00:02:53,730 --> 00:03:00,300 And then while it is some number which in this case it will be some one sum to some three. 36 00:03:00,930 --> 00:03:08,520 So while it is some number, we want to print out that number that is being taken off the stack. 37 00:03:09,990 --> 00:03:10,620 And what do we get? 38 00:03:10,650 --> 00:03:18,300 We get 3 to 1, and that is because stacks are last in, first out. 39 00:03:18,360 --> 00:03:23,400 So I just wanted to show you these quick examples of other ways that we can use if. 40 00:03:24,560 --> 00:03:34,490 Examples or wallet in order to match on single statements and then execute some code based on those 41 00:03:34,490 --> 00:03:35,540 match statements.