0:00:00.000,0:00:05.737 In this section, I wanna show you can take[br]a simple test, like startsWith("A"), and 0:00:05.737,0:00:11.402 use, the notion of AND, and OR, to combine[br]it with other tests to sort of put 0:00:11.402,0:00:17.721 together a more complicated test. So this[br]is called Boolean logic. So the way this 0:00:17.721,0:00:23.313 is gonna work, is, in code, the notion of[br]AND is the, the symbol for that two 0:00:23.313,0:00:28.905 ampersands run together (&&). And the, the[br]symbol for OR is two vertical bars (||), 0:00:28.905,0:00:33.994 put together. So let me show you what that[br]looks like. So here's some code. And it 0:00:33.994,0:00:38.906 has, the first test just says if the name[br]starts with "A", just as we've seen before, 0:00:39.081,0:00:43.466 and that test is, it's complete and[br]functional. So that is not changed by 0:00:43.466,0:00:48.319 adding the notion of Boolean logic. So for[br]Boolean logic, what we do is we take that 0:00:48.319,0:00:53.056 test and we follow it with two ampersands.[br]So you would pronounce that as, AND. And 0:00:53.056,0:00:57.850 then it's followed by a second test. The[br]second test is also complete and makes 0:00:57.850,0:01:02.469 sense on its own. So, what this does is it[br]just takes two tests and it puts them 0:01:02.469,0:01:06.905 together, and it says, well. For this[br]overall if-test to be true, both of these 0:01:06.905,0:01:10.976 subparts have to be true. So the[br]components are, well here, I'll, I'll run 0:01:10.976,0:01:15.433 it. So what this says is, names that begin[br]with "A". That has to be true. And the name 0:01:15.433,0:01:20.054 has to end with "y". So if I run it, we just[br]get this, you know, kinda shorter list of 0:01:20.054,0:01:24.733 names that begin with "A" and end with "y".[br]Syntactically like I said it has the two 0:01:24.733,0:01:29.569 tests, each of which is complete. They're[br]joined with AND or, OR as we'll see in 0:01:29.569,0:01:34.406 a minute. And then finally there is still[br]this one set of parentheses, a left most 0:01:34.406,0:01:39.359 parentheses and a right most, a right most[br]parenthesis, around the entire thing. So 0:01:39.359,0:01:43.463 I'll do a bunch of examples, like this. A[br]couple other, one other thing to point out 0:01:43.463,0:01:47.422 about this, in this case what happened is,[br]the test is kind of long, right? I have 0:01:47.422,0:01:51.140 this whole startsWith part, and the[br]ampersand, so if I did it all on one line, 0:01:51.140,0:01:55.148 it gets a little, a little long. So what's[br]happened in this case is I, actually I hit 0:01:55.148,0:01:59.107 return after the ampersand. I went down[br]here and I hit the space bar, to get the 0:01:59.107,0:02:03.018 row over here and kind of line it up. So I[br]wrote the second test on a second line. 0:02:03.163,0:02:07.025 That's optional but you can do it. Putting[br]in spaces and stuff like that doesn't 0:02:07.025,0:02:10.780 upset the code. So, I'm, always my[br]examples I'll sort of neaten up in this 0:02:10.780,0:02:14.872 way, Where I'll tend to write one test per[br]line, and then I'll align them this way. 0:02:14.872,0:02:19.217 So here's the second test. The only thing[br]that's a little confusing is to note that 0:02:19.217,0:02:23.151 there are two parentheses are required[br]here. This, this first one just balances 0:02:23.151,0:02:27.530 the parentheses for the endsWith. And then[br]the second one, is the one that covers the 0:02:27.530,0:02:31.657 entire test, so it matches up to the, that[br]first one. So if you leave that out, 0:02:31.657,0:02:35.734 actually I can illustrate this, so it's a[br]pretty easy error to leave that one out, 0:02:35.734,0:02:39.660 'cuz you have to kinda realize alright I[br]need two there. So in that case, not 0:02:39.660,0:02:43.586 always, but the run button for the, just[br]for this class, will try to give you an 0:02:43.586,0:02:47.514 error message, like oh, it looks like[br]there's a missing parentheses there. So 0:02:47.514,0:02:53.111 now form it that way we'll get them,[br]we're still good. As I said before each of 0:02:53.111,0:02:58.640 these tests is complete and stand on its[br]own. So just syntactly just the way we did 0:02:58.640,0:03:03.900 things before. There's this one form of[br]the code that looks right but is wrong. 0:03:03.900,0:03:09.285 And so I'll create that here. So[br]if you just write it this way. So I'll 0:03:09.285,0:03:14.796 just sort of pronounce it. row.getField("name"), that startsWith("a") AND 0:03:14.796,0:03:19.707 endsWith("y"). So just[br]to the ear to a human, they would know 0:03:19.707,0:03:24.531 what that means, but this code does not[br]work. The problem is the second term. On 0:03:24.531,0:03:28.457 its own, doesn't make sense. Right?[br]Doesn't just stand on its own like ends 0:03:28.457,0:03:32.598 with, well it doesn't make sense. Usually[br]what we need is, we're gonna put in a 0:03:32.598,0:03:36.901 cursor here, we would need row.getField("name")[br]or "rank" or whatever it's gonna 0:03:36.901,0:03:41.311 be .endsWith. So this is not working.[br]Each, each, to the left and the right of 0:03:41.311,0:03:45.237 the ampersand, each task has to be[br]complete. So in this case, I'll just sort 0:03:45.237,0:03:50.589 of hit undo in Firefox here, the, if[br]we wanna be talking about name, like we 0:03:50.589,0:03:55.292 spell it out for the first test, and then[br]we also just completely spell it out for 0:03:55.292,0:03:59.994 the second test. So each test makes sense[br]to the computer. Alrighty, So, I'm gonna 0:03:59.994,0:04:04.525 try another example here. Let's see. So[br]right now, if I run this, it just shows 0:04:04.525,0:04:09.399 all the "A" names, which is quite a lot.[br]What the problem statement says is, change 0:04:09.399,0:04:14.121 the code so it prints the names that start[br]with "A" and the rank is less than 50. So, 0:04:14.121,0:04:18.791 oh here's, here's the first test, and I'll[br]add two ampersands, and return let's 0:04:18.791,0:04:23.845 say row, that starts, that startsWith("A")[br]is one test and now we're gonna add, I'm 0:04:23.845,0:04:28.898 gonna combine it with an AND, with the[br]second test, where I'll say rank, oh let's 0:04:28.898,0:04:34.016 say less than or equal to 50. So I[br]think I'll try it, yeah so that works. So 0:04:34.016,0:04:39.495 we still get "A" names but now we're just[br]getting up to rank 50. I'm just gonna try 0:04:39.495,0:04:44.534 a third example here. Alright, now we'll[br]do an example with OR. Change the code 0:04:44.534,0:04:49.384 below, so it prints rows where the[br]following is true. Name starts with "X", or 0:04:49.384,0:04:54.233 the name stars with "Y", or the name stars[br]with "C". So if I just run, run it right 0:04:54.233,0:05:02.722 now, the code that's there just does "X". So[br]I wanna use OR. And we'll copy this. 0:05:02.722,0:05:10.222 So by using an OR-test. You make[br]multiple ways for the overall if-test to 0:05:10.222,0:05:15.516 be true. It's like, well, the if-test were[br]true if this one is true, or if this other 0:05:15.516,0:05:20.940 thing is true. So it's kind of a widening.[br]So here I'll say, OR row.getField - "Y". 0:05:20.940,0:05:27.648 So, for the previous run, we only got "X".[br]Alright? So I'm gonna run this. Oh, so now 0:05:27.648,0:05:33.878 we get "X" and "Y". So there's "Yusuf" and[br]"Yeritza". Notice that I, my goal 0:05:33.878,0:05:38.950 ultimately was to show "X" or "Y" or "Z", but I[br]think it is kinda nice if you get the code 0:05:38.950,0:05:43.961 into a kind of half built state, but where[br]it makes sense. You know, just try running 0:05:43.961,0:05:48.429 it and kind of verify, oh that works[br]before going on to do the whole thing. 0:05:48.429,0:05:53.260 That's kind of a classic computer code[br]rule of thumb; don't try and do the entire 0:05:53.260,0:05:58.203 thing in one step, OR startsWith("Z"). So, I[br]guess partly what I'm showing here is. You 0:05:58.203,0:06:02.927 can have multiple ORs and multiple ANDs and[br]string things together. So let's 0:06:02.927,0:06:07.301 try that, There it goes, Quite a few "Z"[br]names. So there we have it, "X" or "Y" or" "Z, 0:06:07.476,0:06:12.375 so this shows the two vertical bars, and[br]then in this case I have strung together 0:06:12.375,0:06:16.691 three things. For this class, I will only,[br]I'll use either a bunch of things 0:06:16.691,0:06:21.298 connected with AND or a bunch of things[br]connected with OR. I won't combine them. 0:06:21.298,0:06:25.964 Combine them just brings up some other[br]cases that are kind of interesting but I 0:06:25.964,0:06:30.552 not, I don't really want to get into. They[br]don't really help a lot. Other thing I 0:06:30.552,0:06:33.849 should mention about this, alright so I[br]should just apologize to this. This 0:06:33.849,0:06:37.565 ampersand business is sort of a historical[br]accident, or the vertical bar business. 0:06:37.565,0:06:41.144 Language, influencial language chose this[br]in, like the mid'70s. And once one 0:06:41.144,0:06:44.814 language had chosen this symbol to mean[br]OR, some other languages thought, oh, well 0:06:44.814,0:06:48.347 we should just use that convention. And so[br]it just kinda snowballed, where now, 0:06:48.347,0:06:51.880 that's a very common convention. So I felt[br]like, well, it's kind of obscure, but. 0:06:51.880,0:06:55.955 That's the convention so we should just go[br]ahead and learn that one. Alright, So, 0:06:55.955,0:06:59.927 let's scroll down here a little bit. So[br]actually, what I have set up is just a 0:06:59.927,0:07:04.209 large number of examples here. And there's[br]a show solution button here, so if you 0:07:04.209,0:07:08.543 want practice or to review these examples[br]I've done, you could come back and it's 0:07:08.543,0:07:12.670 all sorted here. What I'll is I'll just[br]try the, the first six. So, I'll type in 0:07:12.670,0:07:16.539 the code for those and I'll leave the[br]others as kind of extra practice for 0:07:16.539,0:07:21.716 people who want it. Okay, so the first one[br]says, name starts with "Ab", or starts with 0:07:21.716,0:07:28.182 "Ac". So I'll say there's some code here[br]that we start with already. So it starts 0:07:28.182,0:07:39.366 with "Ab". And what was it? OR starts with[br]"Ac". So this one starts with here, So this 0:07:39.366,0:07:48.795 should be an OR, Two different or's. Let's[br]try that one. So we got "A", "Ac" Where's 0:07:48.795,0:07:56.304 the "Ac" name? Oh. Look I made a bug. I typed[br]"Ab" twice. Okay. There we go. 0:07:56.304,0:08:02.010 Ok, there's an "Ac". That showed that interesting[br]example of a bug, where sometimes bugs are 0:08:02.010,0:08:07.578 syntax errors where you hit the run button[br]and it, it just, you know, it, it crashes 0:08:07.578,0:08:12.263 and you get some red output. But[br]sometimes a bug is just that. I typed 0:08:12.263,0:08:16.494 something that does mean something to the[br]computer, but it's not what I intended. 0:08:16.494,0:08:20.462 And so then the output is not what I[br]expected, then I'm a little bit confused. 0:08:20.462,0:08:24.482 So that's the more higher level kind of[br]bug in this course. It's fairly 0:08:24.482,0:08:28.713 common with computers. Okay, let's see,[br]next one. Name starts with "Ab", or 0:08:28.713,0:08:33.533 "Ac", or "Al". Oh, I see. So this just[br]extends. This just shows that you can have 0:08:33.533,0:08:38.359 three. So I'll say vertical bar.[br]I'll paste this in. So it was "Ac", 0:08:38.359,0:08:42.920 so "Ab" and "Ac" doesn't give us a lot but[br]with "Al" you know it's quite a lot. 0:08:45.560,0:08:55.578 Okay. So the next one was, name starts[br]with O and ends with A. So I'll say 0:08:55.578,0:09:08.877 starts, I'll just translate it. Starts[br]with "O" AND ends with "a". Alright. Let's 0:09:08.877,0:09:16.271 try that. Oh, there's only one, "Olivia". How[br]bout, starts with O and gender is girl? 0:09:16.271,0:09:23.756 So, we'll just get gender right here, and[br]then we test that is not with startsWith 0:09:23.756,0:09:30.329 endsWith, but just with ==.[br]So, O AND girl. Oh, there's only two. 0:09:30.329,0:09:36.400 So we get Olive. Okay,[br]name ends with "a" and gender is what? 0:09:36.980,0:09:43.974 Change this to name.endsWith("a"), and[br]per my previous example, my previous claim, I'll just cut that out. 0:09:43.974,0:09:50.968 Now it's half built right, name ends with[br]"a". But I could run that and sorta verify, 0:09:50.968,0:09:58.788 all rigt that's working. And then, take[br]your working thing, and extend it. What 0:09:58.788,0:10:06.272 did I want? In this case I wanted oh,[br]names ends with "a" and gender is blank. 0:10:06.272,0:10:16.198 Okay. Jesus, Lyle. Girl names neither.[br]Boy. Oh, well, there's a few, Joshua, 0:10:16.198,0:10:23.240 Ezra. Okay, I'll do this last one, number[br]six Rank is less than ten, and gender is 0:10:23.240,0:10:29.149 girl. So I'll change this to "rank". Instead[br]of endsWith. I'll say, less than or equal to ten. 0:10:29.149,0:10:34.181 And, so, Now I'm not using startsWith, or[br]endsWith for either of these but just 0:10:34.181,0:10:39.532 notice each one of those is a complete and[br]correct test as we discussed before. That 0:10:39.532,0:10:44.373 one is, and that one is and I'm just[br]joining them from there. So rank is less 0:10:44.373,0:10:49.581 than ten, and gender in this case is girl.[br]Let's try that. So that makes sense. We 0:10:49.581,0:10:53.668 just get one, two, three, four of them.[br]One through ten girl names. This one's 0:10:53.668,0:10:57.969 kind of interesting in that this, this I[br]think has a sensible English translation. 0:10:57.969,0:11:02.171 What this is, is. What this says is top[br]ten girl names, And then, We can phrase 0:11:02.171,0:11:06.576 that as this AND thing. Where rank is less[br]than or equal to ten and gender is girl. Or indeed 0:11:06.576,0:11:10.927 ultimately we can phrase it as code. So[br]just get it down to, to where the computer 0:11:10.927,0:11:15.116 can actually do it. So there's a few more[br]problems here and the solutions all 0:11:15.116,0:11:19.359 available. So this is a good opportunity[br]to come and review what I did or try a 0:11:19.359,0:11:23.603 little bit of practice before we do the[br]exercises. Cuz these, in some sense, are - 0:11:23.603,0:11:28.007 computer languages have now gotten big[br]enough that I can really we can have a lot 0:11:28.007,0:11:29.780 of different [inaudible] alright.