1 00:00:00,170 --> 00:00:04,200 All right, it's hot out there let's do an ice cream example. 2 00:00:04,200 --> 00:00:07,080 For those of you watching at home, you probably don't know about this place, but 3 00:00:07,080 --> 00:00:10,670 there is a place here in Portland that likes to make weird ice cream flavors, and 4 00:00:10,670 --> 00:00:14,600 it mixes sweet and savory, and it's a good combination and so 5 00:00:14,600 --> 00:00:15,620 I thought this might be a good time. 6 00:00:15,620 --> 00:00:19,246 It's hot outside, it's really hot today, so let's go make some ice cream 7 00:00:19,246 --> 00:00:24,640 [INAUDIBLE] you guys [INAUDIBLE] you guys know this song right come on [LAUGH] Okay, 8 00:00:24,640 --> 00:00:27,170 so, I have two arrays. 9 00:00:27,170 --> 00:00:31,830 I have a sweet flavor and I have a savory flavor and these are actually real. 10 00:00:31,830 --> 00:00:35,060 They really do have barbecue sauce and they really do have baked beans. 11 00:00:35,060 --> 00:00:39,320 So, what we're going to do is we're going to mix these two together. 12 00:00:39,320 --> 00:00:41,440 And we're going to do that through nesting two for loops. 13 00:00:42,490 --> 00:00:46,530 So let's go ahead and we'll say, we're gonna use the for each loop here. 14 00:00:46,530 --> 00:00:50,050 For each of the sweets, the sweet flavors. 15 00:00:50,050 --> 00:00:53,320 And then we want every single one of the sweet ones to mix with the other ones. 16 00:00:53,320 --> 00:00:56,330 We wanna see all the possible combinations that we can make with this so 17 00:00:56,330 --> 00:00:57,810 we're gonna nest the loop. 18 00:00:57,810 --> 00:00:59,070 So, another for loop. 19 00:00:59,070 --> 00:01:01,960 So each time, each one of these we're gonna run another one of these loops. 20 00:01:01,960 --> 00:01:06,120 You see this quite a bit, and sometimes it's using the Is and the Js. 21 00:01:06,120 --> 00:01:10,400 I keep on pressing tab, I've been moved into the IDE world in writing these 22 00:01:10,400 --> 00:01:11,840 courses and I've been pressing tab. 23 00:01:15,866 --> 00:01:18,300 Say %s and %s. 24 00:01:18,300 --> 00:01:24,510 And we're going to pass in the sweet and we're going to pass in the savory. 25 00:01:24,510 --> 00:01:25,630 Okay. So let's run it and 26 00:01:25,630 --> 00:01:28,100 then we'll take a look at, we'll walk it really quick. 27 00:01:32,030 --> 00:01:34,040 Love that I have a java ice cream. 28 00:01:35,930 --> 00:01:36,430 Alright. 29 00:01:39,750 --> 00:01:44,280 Okay, so this is the one that popped out here, this very last one here. 30 00:01:44,280 --> 00:01:46,260 This is the barbecue sauce. 31 00:01:46,260 --> 00:01:48,320 And let's see if I can make this actually longer. 32 00:01:48,320 --> 00:01:52,710 Let's see the whole thing. 33 00:01:52,710 --> 00:01:53,720 And I'll bring the loop back down. 34 00:01:53,720 --> 00:01:58,578 Nope, all right, so alright, so 35 00:01:58,578 --> 00:02:03,610 caramel is the first sweet flavor. 36 00:02:03,610 --> 00:02:05,760 So what's gonna happen is it's gonna go into this for loop and 37 00:02:05,760 --> 00:02:08,320 sweet is gonna be set to caramel. 38 00:02:09,600 --> 00:02:11,920 Next, we're gonna loop through each one of the savory ones but 39 00:02:11,920 --> 00:02:13,680 we're gonna keep sweet because it's in the top loop. 40 00:02:13,680 --> 00:02:17,560 And then in the inside loop we're gonna hit savory. 41 00:02:17,560 --> 00:02:18,800 Does that make sense? 42 00:02:18,800 --> 00:02:21,950 It happens quite a bit when you need to do cross-products of things and 43 00:02:21,950 --> 00:02:24,340 combinations of, you want to loop through all of these and 44 00:02:24,340 --> 00:02:27,670 see what happens if you do a combination with all of these things. 45 00:02:27,670 --> 00:02:28,590 So it's a nested for loop. 46 00:02:28,590 --> 00:02:31,168 I just wanted to show you that cause you will see those.