1 00:00:00,180 --> 00:00:03,870 Before we start, did you try solving the workbook yourself? 2 00:00:03,900 --> 00:00:09,660 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,470 --> 00:00:12,640 Welcome to Workbook 6.10. 4 00:00:12,660 --> 00:00:16,800 This one seems a little long, so let's just jump right into it. 5 00:00:16,890 --> 00:00:23,040 Create a for loop that runs through the length of the toppings array inside the four loop print each 6 00:00:23,040 --> 00:00:24,900 index number followed by a dot. 7 00:00:24,930 --> 00:00:28,170 Let's start with this because it seems really easy. 8 00:00:28,260 --> 00:00:34,500 So here we've got our toppings array, which whose length depends on whatever the user inputs. 9 00:00:34,530 --> 00:00:36,360 That's pretty cool, if you ask me. 10 00:00:36,570 --> 00:00:39,540 So we'll say four and I is equal to zero. 11 00:00:39,660 --> 00:00:42,570 I is smaller than toppings dot length. 12 00:00:42,690 --> 00:00:47,430 We're going to run through the length of the toppings array and every time the loop runs we increase 13 00:00:47,430 --> 00:00:51,090 the counter by one so that we go through every index in the array. 14 00:00:52,220 --> 00:00:58,250 Every time the loop runs, we print each index number followed by a dot. 15 00:00:58,460 --> 00:01:02,930 I'm guessing system that output print line because they're all on separate lines. 16 00:01:03,170 --> 00:01:03,710 Oh no. 17 00:01:03,710 --> 00:01:06,320 Beside the number, we need to pick up the user's topping. 18 00:01:06,320 --> 00:01:13,910 So what we'd have to do is say print, not print line, and then we'll print the index number followed 19 00:01:13,910 --> 00:01:15,560 by a dot. 20 00:01:16,010 --> 00:01:21,890 And I'm guessing after we would have to print a new line so we can print a new line by either saying 21 00:01:21,890 --> 00:01:25,100 print line or by just printing a new line. 22 00:01:26,470 --> 00:01:28,030 Either way, it doesn't matter. 23 00:01:29,500 --> 00:01:30,700 Beside the number. 24 00:01:30,700 --> 00:01:32,470 Pick up the user's topping. 25 00:01:32,920 --> 00:01:34,090 All right. 26 00:01:35,040 --> 00:01:42,390 So after we print whatever index is currently being iterated through, we're going to say toppings at 27 00:01:42,390 --> 00:01:46,560 Index II is equal to scan next line. 28 00:01:47,040 --> 00:01:53,610 So whatever the user inputs we are going to store as an element inside of the toppings array, and then 29 00:01:53,610 --> 00:01:55,620 we print our new line. 30 00:01:56,280 --> 00:01:59,760 That should be it for task number one. 31 00:02:00,300 --> 00:02:00,630 Yep. 32 00:02:00,630 --> 00:02:02,230 Where did that store every topic? 33 00:02:02,270 --> 00:02:04,110 The user inputs and the toppings array. 34 00:02:04,140 --> 00:02:10,860 Task two is to create a for loop that runs through the length of the array and prints each topping. 35 00:02:10,860 --> 00:02:16,860 So after we have registered all of the toppings they want, then we confirm with them. 36 00:02:16,860 --> 00:02:19,380 So here we're going to create another for loop. 37 00:02:19,770 --> 00:02:20,160 You know what? 38 00:02:20,160 --> 00:02:21,390 Let's just copy this one. 39 00:02:23,890 --> 00:02:25,990 Here are the toppings you ordered. 40 00:02:25,990 --> 00:02:29,110 So we're just going to print line. 41 00:02:29,960 --> 00:02:33,230 Whatever the current index is plus. 42 00:02:34,650 --> 00:02:36,870 The topping at that index. 43 00:02:37,350 --> 00:02:38,700 Is that all they want? 44 00:02:39,150 --> 00:02:39,930 Beautiful. 45 00:02:43,190 --> 00:02:45,020 And I think we're good. 46 00:02:46,570 --> 00:02:48,960 Now you can just visualize the runtime. 47 00:02:48,970 --> 00:02:50,500 I love doing that. 48 00:02:50,770 --> 00:02:52,060 I'll put one here. 49 00:02:52,660 --> 00:02:54,670 I'll put one here. 50 00:03:01,290 --> 00:03:01,920 Alrighty. 51 00:03:01,920 --> 00:03:06,120 So here scanned up next and waits for me to enter an integer. 52 00:03:06,150 --> 00:03:08,050 How many topics do you want? 53 00:03:08,070 --> 00:03:10,200 Let's just do what's on there in the part. 54 00:03:10,200 --> 00:03:11,220 We'll say three. 55 00:03:11,910 --> 00:03:17,010 So now this array is going to have a length of three based on what we inputted. 56 00:03:17,040 --> 00:03:18,360 That's pretty cool. 57 00:03:19,530 --> 00:03:21,360 Because each element is a string. 58 00:03:21,390 --> 00:03:23,040 They start off being null. 59 00:03:23,340 --> 00:03:25,050 Here we're going to change that. 60 00:03:25,050 --> 00:03:28,380 So our for loop starts at I being zero. 61 00:03:29,010 --> 00:03:30,780 Here we print zero. 62 00:03:32,160 --> 00:03:35,430 Scan next line is going to wait for me to enter a value. 63 00:03:37,200 --> 00:03:38,190 I will enter. 64 00:03:38,190 --> 00:03:39,990 I don't know, Onion. 65 00:03:42,230 --> 00:03:48,230 Onion is going to get picked up by scan next line and get stored as an element at index zero. 66 00:03:48,830 --> 00:03:49,310 Oh God. 67 00:03:49,310 --> 00:03:50,120 I press enter. 68 00:03:51,060 --> 00:03:51,840 Beautiful. 69 00:03:52,560 --> 00:03:53,880 Then it prints a new line. 70 00:03:54,820 --> 00:03:57,160 All right, now I a plus plus takes us. 71 00:03:57,820 --> 00:03:59,590 Ah, you know what? 72 00:03:59,590 --> 00:04:03,790 Scan next line already moves to a new line, so I don't need this. 73 00:04:04,510 --> 00:04:06,180 Let's restart the runtime. 74 00:04:06,190 --> 00:04:07,540 Sorry about that. 75 00:04:08,840 --> 00:04:09,320 Um. 76 00:04:09,320 --> 00:04:10,640 How many topics do you want? 77 00:04:10,670 --> 00:04:11,410 Three. 78 00:04:11,420 --> 00:04:18,140 So I start at zero printing zero and on the same line it's asking us to input a value. 79 00:04:18,170 --> 00:04:23,510 I'm going to input onion that's going to get picked up and stored as an element at index zero. 80 00:04:23,540 --> 00:04:24,440 Perfect. 81 00:04:25,810 --> 00:04:27,640 Now I equals one. 82 00:04:29,350 --> 00:04:30,760 So I step over this scan. 83 00:04:30,940 --> 00:04:33,060 Next line waits for me to enter a value. 84 00:04:33,070 --> 00:04:35,140 We will enter mushroom. 85 00:04:36,770 --> 00:04:39,650 That's going to get stored as an element that index one. 86 00:04:40,320 --> 00:04:46,620 Now I equals to that prince scan next line is going to wait for me to enter a value. 87 00:04:46,650 --> 00:04:48,300 Let's enter, Pepper. 88 00:04:49,220 --> 00:04:55,010 And that's going to get stored as an element that index to I a plus plus is going to increase I to now 89 00:04:55,010 --> 00:04:59,930 equal three three is not smaller than the length of the array which is also three. 90 00:04:59,930 --> 00:05:01,970 So our for loop breaks. 91 00:05:03,180 --> 00:05:03,660 Thank you. 92 00:05:03,720 --> 00:05:08,250 Here are the toppings you ordered, and then this loop is just going to run through the length of the 93 00:05:08,250 --> 00:05:11,040 toppings array and print each one. 94 00:05:12,930 --> 00:05:14,340 Starting at zero. 95 00:05:14,370 --> 00:05:16,050 It's going to print onion. 96 00:05:17,190 --> 00:05:20,460 Now I equals one printing mushroom. 97 00:05:21,090 --> 00:05:23,550 Now I equals to printing pepper. 98 00:05:24,810 --> 00:05:26,700 And now I have plus plus increases. 99 00:05:26,700 --> 00:05:27,930 I to be three. 100 00:05:27,930 --> 00:05:33,180 Three is not smaller than the length of the array three so the four loop breaks. 101 00:05:34,470 --> 00:05:37,800 And then it says, Press anything to confirm your order scan. 102 00:05:38,010 --> 00:05:40,800 Next line is going to prompt me to enter anything. 103 00:05:42,090 --> 00:05:42,510 Great. 104 00:05:42,510 --> 00:05:47,850 A driver is on the way, scanned up close and we are done. 105 00:05:49,380 --> 00:05:52,410 I really hope you enjoyed this breakpoint session.