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,810 --> 00:00:12,730 Welcome to Workbook 6.4. 4 00:00:12,760 --> 00:00:17,710 Task one is to pick up the user's response and store it in a string variable. 5 00:00:17,710 --> 00:00:26,530 So here I'm going to say string response is equal to scanner or scan next line. 6 00:00:28,350 --> 00:00:36,480 And workbook 6.4 is basically identical to 6.3, just like in workbook 6.3, we're going to index every 7 00:00:36,480 --> 00:00:42,510 single element inside of the store array and for every single element that we index, we're going to 8 00:00:42,510 --> 00:00:46,440 compare it against whatever the user inputs. 9 00:00:47,420 --> 00:00:53,870 And if the user's response matches one of the aisles inside of our store, then we are going to print. 10 00:00:53,870 --> 00:00:59,660 We have that in aisle, whatever I equals when this condition evaluates to true. 11 00:01:00,170 --> 00:01:04,400 And once we find what the user is looking for, we break the loop. 12 00:01:04,400 --> 00:01:05,990 And that is all. 13 00:01:06,260 --> 00:01:09,290 This is extremely identical to workbook 6.3. 14 00:01:09,290 --> 00:01:13,160 It doesn't really introduce anything new aside from user interactivity. 15 00:01:13,160 --> 00:01:18,860 So let's go ahead and put one breakpoint at the line where you define the for loop, and we are going 16 00:01:18,860 --> 00:01:21,890 to visualize the runtime right now. 17 00:01:30,350 --> 00:01:33,520 So right now, next line is waiting for me to enter a string. 18 00:01:33,530 --> 00:01:36,020 I will enter the value bananas. 19 00:01:38,730 --> 00:01:41,550 All right, so their response equals bananas. 20 00:01:41,580 --> 00:01:47,070 This loop is going to keep running so long as I is smaller than the length of the store array. 21 00:01:48,880 --> 00:01:49,640 When I. 22 00:01:49,660 --> 00:01:51,190 Equals zero. 23 00:01:51,370 --> 00:01:55,180 The element that index zero of our store array is apples. 24 00:01:55,180 --> 00:01:58,360 Apples does not equal our response of bananas. 25 00:01:58,360 --> 00:02:01,210 So this will evaluate to false getting skipped. 26 00:02:02,810 --> 00:02:06,350 Now during the second run of our loop I equals one. 27 00:02:06,380 --> 00:02:11,150 The element at index one bananas does equal our response. 28 00:02:11,150 --> 00:02:12,950 So this will evaluate to true. 29 00:02:13,340 --> 00:02:16,010 We have bananas in aisle one. 30 00:02:17,420 --> 00:02:18,410 We're done searching. 31 00:02:18,410 --> 00:02:21,500 We can break the loop and continue with the runtime. 32 00:02:22,010 --> 00:02:22,810 Let's do this again. 33 00:02:22,820 --> 00:02:23,940 That was kind of fun. 34 00:02:23,960 --> 00:02:28,700 Let's say the user is looking for autonomy. 35 00:02:30,380 --> 00:02:37,460 The loop starts with I equaling zero when I equals zero were grabbing the element at index zero. 36 00:02:37,460 --> 00:02:43,280 So apples does not equal tw this if statement is going to evaluate the false. 37 00:02:44,980 --> 00:02:48,050 During the second run of our loop I equals one. 38 00:02:48,070 --> 00:02:54,630 The element at index one is bananas, which does not equal t during the third run of our loop. 39 00:02:54,640 --> 00:03:02,290 I equals to the element and index to candy does not equal t, so that's going to get skipped. 40 00:03:02,770 --> 00:03:08,290 Index three chocolate does not equal t now I equals for the element. 41 00:03:08,290 --> 00:03:11,590 That index for coffee does not equal t. 42 00:03:12,910 --> 00:03:16,600 And now during the last run of our loop I equals five. 43 00:03:16,600 --> 00:03:20,590 The element of index five does equal our response of T. 44 00:03:20,620 --> 00:03:22,390 So this evaluates to true. 45 00:03:22,420 --> 00:03:25,270 We have that in aisle number five. 46 00:03:25,720 --> 00:03:28,450 And now that we're done searching, we break the loop. 47 00:03:30,660 --> 00:03:34,960 And now let's imagine that the user enters something that isn't in our store. 48 00:03:34,980 --> 00:03:38,640 So let's say they are looking for, I don't know, crackers. 49 00:03:40,010 --> 00:03:42,500 When the loop runs, I equals zero. 50 00:03:42,530 --> 00:03:48,740 The element of index zero apples does not equal crackers, so this statement will get skipped. 51 00:03:49,190 --> 00:03:56,390 And no matter what I ends up equaling, none of the elements in the array are going to equal crackers. 52 00:03:56,390 --> 00:04:01,790 So this is going to keep going where the if statement is always going to evaluate the false until we 53 00:04:01,790 --> 00:04:08,510 get to our very last run where I ends up equaling five, the element that index five does not equal 54 00:04:08,510 --> 00:04:09,260 crackers. 55 00:04:09,260 --> 00:04:13,490 So now I a plus plus is going to increase I to six. 56 00:04:13,610 --> 00:04:15,950 The length of the store array is six. 57 00:04:15,950 --> 00:04:19,430 Six is not smaller than six, so the loop ends. 58 00:04:21,420 --> 00:04:23,820 And now we can just terminate the runtime. 59 00:04:24,270 --> 00:04:30,320 So the only difference between this workbook and workbook 6.3 and this one is more dynamic. 60 00:04:30,330 --> 00:04:33,180 The user can search for anything that they want. 61 00:04:33,630 --> 00:04:39,300 If we find what they're looking for, we print the following message break the loop to stop our search. 62 00:04:39,300 --> 00:04:45,300 But if we don't find what they're looking for, the for loop is going to run to completion, not printing 63 00:04:45,300 --> 00:04:46,080 anything.