[Script Info] Title: [Events] Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text Dialogue: 0,0:00:00.00,0:00:05.74,Default,,0000,0000,0000,,In this section, I wanna show you can take\Na simple test, like startsWith("A"), and Dialogue: 0,0:00:05.74,0:00:11.40,Default,,0000,0000,0000,,use, the notion of AND, and OR, to combine\Nit with other tests to sort of put Dialogue: 0,0:00:11.40,0:00:17.72,Default,,0000,0000,0000,,together a more complicated test. So this\Nis called Boolean logic. So the way this Dialogue: 0,0:00:17.72,0:00:23.31,Default,,0000,0000,0000,,is gonna work, is, in code, the notion of\NAND is the, the symbol for that two Dialogue: 0,0:00:23.31,0:00:28.90,Default,,0000,0000,0000,,ampersands run together (&&). And the, the\Nsymbol for OR is two vertical bars (||), Dialogue: 0,0:00:28.90,0:00:33.99,Default,,0000,0000,0000,,put together. So let me show you what that\Nlooks like. So here's some code. And it Dialogue: 0,0:00:33.99,0:00:38.91,Default,,0000,0000,0000,,has, the first test just says if the name\Nstarts with "A", just as we've seen before, Dialogue: 0,0:00:39.08,0:00:43.47,Default,,0000,0000,0000,,and that test is, it's complete and\Nfunctional. So that is not changed by Dialogue: 0,0:00:43.47,0:00:48.32,Default,,0000,0000,0000,,adding the notion of Boolean logic. So for\NBoolean logic, what we do is we take that Dialogue: 0,0:00:48.32,0:00:53.06,Default,,0000,0000,0000,,test and we follow it with two ampersands.\NSo you would pronounce that as, AND. And Dialogue: 0,0:00:53.06,0:00:57.85,Default,,0000,0000,0000,,then it's followed by a second test. The\Nsecond test is also complete and makes Dialogue: 0,0:00:57.85,0:01:02.47,Default,,0000,0000,0000,,sense on its own. So, what this does is it\Njust takes two tests and it puts them Dialogue: 0,0:01:02.47,0:01:06.90,Default,,0000,0000,0000,,together, and it says, well. For this\Noverall if-test to be true, both of these Dialogue: 0,0:01:06.90,0:01:10.98,Default,,0000,0000,0000,,subparts have to be true. So the\Ncomponents are, well here, I'll, I'll run Dialogue: 0,0:01:10.98,0:01:15.43,Default,,0000,0000,0000,,it. So what this says is, names that begin\Nwith "A". That has to be true. And the name Dialogue: 0,0:01:15.43,0:01:20.05,Default,,0000,0000,0000,,has to end with "y". So if I run it, we just\Nget this, you know, kinda shorter list of Dialogue: 0,0:01:20.05,0:01:24.73,Default,,0000,0000,0000,,names that begin with "A" and end with "y".\NSyntactically like I said it has the two Dialogue: 0,0:01:24.73,0:01:29.57,Default,,0000,0000,0000,,tests, each of which is complete. They're\Njoined with AND or, OR as we'll see in Dialogue: 0,0:01:29.57,0:01:34.41,Default,,0000,0000,0000,,a minute. And then finally there is still\Nthis one set of parentheses, a left most Dialogue: 0,0:01:34.41,0:01:39.36,Default,,0000,0000,0000,,parentheses and a right most, a right most\Nparenthesis, around the entire thing. So Dialogue: 0,0:01:39.36,0:01:43.46,Default,,0000,0000,0000,,I'll do a bunch of examples, like this. A\Ncouple other, one other thing to point out Dialogue: 0,0:01:43.46,0:01:47.42,Default,,0000,0000,0000,,about this, in this case what happened is,\Nthe test is kind of long, right? I have Dialogue: 0,0:01:47.42,0:01:51.14,Default,,0000,0000,0000,,this whole startsWith part, and the\Nampersand, so if I did it all on one line, Dialogue: 0,0:01:51.14,0:01:55.15,Default,,0000,0000,0000,,it gets a little, a little long. So what's\Nhappened in this case is I, actually I hit Dialogue: 0,0:01:55.15,0:01:59.11,Default,,0000,0000,0000,,return after the ampersand. I went down\Nhere and I hit the space bar, to get the Dialogue: 0,0:01:59.11,0:02:03.02,Default,,0000,0000,0000,,row over here and kind of line it up. So I\Nwrote the second test on a second line. Dialogue: 0,0:02:03.16,0:02:07.02,Default,,0000,0000,0000,,That's optional but you can do it. Putting\Nin spaces and stuff like that doesn't Dialogue: 0,0:02:07.02,0:02:10.78,Default,,0000,0000,0000,,upset the code. So, I'm, always my\Nexamples I'll sort of neaten up in this Dialogue: 0,0:02:10.78,0:02:14.87,Default,,0000,0000,0000,,way, Where I'll tend to write one test per\Nline, and then I'll align them this way. Dialogue: 0,0:02:14.87,0:02:19.22,Default,,0000,0000,0000,,So here's the second test. The only thing\Nthat's a little confusing is to note that Dialogue: 0,0:02:19.22,0:02:23.15,Default,,0000,0000,0000,,there are two parentheses are required\Nhere. This, this first one just balances Dialogue: 0,0:02:23.15,0:02:27.53,Default,,0000,0000,0000,,the parentheses for the endsWith. And then\Nthe second one, is the one that covers the Dialogue: 0,0:02:27.53,0:02:31.66,Default,,0000,0000,0000,,entire test, so it matches up to the, that\Nfirst one. So if you leave that out, Dialogue: 0,0:02:31.66,0:02:35.73,Default,,0000,0000,0000,,actually I can illustrate this, so it's a\Npretty easy error to leave that one out, Dialogue: 0,0:02:35.73,0:02:39.66,Default,,0000,0000,0000,,'cuz you have to kinda realize alright I\Nneed two there. So in that case, not Dialogue: 0,0:02:39.66,0:02:43.59,Default,,0000,0000,0000,,always, but the run button for the, just\Nfor this class, will try to give you an Dialogue: 0,0:02:43.59,0:02:47.51,Default,,0000,0000,0000,,error message, like oh, it looks like\Nthere's a missing parentheses there. So Dialogue: 0,0:02:47.51,0:02:53.11,Default,,0000,0000,0000,,now form it that way we'll get them,\Nwe're still good. As I said before each of Dialogue: 0,0:02:53.11,0:02:58.64,Default,,0000,0000,0000,,these tests is complete and stand on its\Nown. So just syntactly just the way we did Dialogue: 0,0:02:58.64,0:03:03.90,Default,,0000,0000,0000,,things before. There's this one form of\Nthe code that looks right but is wrong. Dialogue: 0,0:03:03.90,0:03:09.28,Default,,0000,0000,0000,,And so I'll create that here. So\Nif you just write it this way. So I'll Dialogue: 0,0:03:09.28,0:03:14.80,Default,,0000,0000,0000,,just sort of pronounce it. row.getField("name"), that startsWith("a") AND Dialogue: 0,0:03:14.80,0:03:19.71,Default,,0000,0000,0000,,endsWith("y"). So just\Nto the ear to a human, they would know Dialogue: 0,0:03:19.71,0:03:24.53,Default,,0000,0000,0000,,what that means, but this code does not\Nwork. The problem is the second term. On Dialogue: 0,0:03:24.53,0:03:28.46,Default,,0000,0000,0000,,its own, doesn't make sense. Right?\NDoesn't just stand on its own like ends Dialogue: 0,0:03:28.46,0:03:32.60,Default,,0000,0000,0000,,with, well it doesn't make sense. Usually\Nwhat we need is, we're gonna put in a Dialogue: 0,0:03:32.60,0:03:36.90,Default,,0000,0000,0000,,cursor here, we would need row.getField("name")\Nor "rank" or whatever it's gonna Dialogue: 0,0:03:36.90,0:03:41.31,Default,,0000,0000,0000,,be .endsWith. So this is not working.\NEach, each, to the left and the right of Dialogue: 0,0:03:41.31,0:03:45.24,Default,,0000,0000,0000,,the ampersand, each task has to be\Ncomplete. So in this case, I'll just sort Dialogue: 0,0:03:45.24,0:03:50.59,Default,,0000,0000,0000,,of hit undo in Firefox here, the, if\Nwe wanna be talking about name, like we Dialogue: 0,0:03:50.59,0:03:55.29,Default,,0000,0000,0000,,spell it out for the first test, and then\Nwe also just completely spell it out for Dialogue: 0,0:03:55.29,0:03:59.99,Default,,0000,0000,0000,,the second test. So each test makes sense\Nto the computer. Alrighty, So, I'm gonna Dialogue: 0,0:03:59.99,0:04:04.52,Default,,0000,0000,0000,,try another example here. Let's see. So\Nright now, if I run this, it just shows Dialogue: 0,0:04:04.52,0:04:09.40,Default,,0000,0000,0000,,all the "A" names, which is quite a lot.\NWhat the problem statement says is, change Dialogue: 0,0:04:09.40,0:04:14.12,Default,,0000,0000,0000,,the code so it prints the names that start\Nwith "A" and the rank is less than 50. So, Dialogue: 0,0:04:14.12,0:04:18.79,Default,,0000,0000,0000,,oh here's, here's the first test, and I'll\Nadd two ampersands, and return let's Dialogue: 0,0:04:18.79,0:04:23.84,Default,,0000,0000,0000,,say row, that starts, that startsWith("A")\Nis one test and now we're gonna add, I'm Dialogue: 0,0:04:23.84,0:04:28.90,Default,,0000,0000,0000,,gonna combine it with an AND, with the\Nsecond test, where I'll say rank, oh let's Dialogue: 0,0:04:28.90,0:04:34.02,Default,,0000,0000,0000,,say less than or equal to 50. So I\Nthink I'll try it, yeah so that works. So Dialogue: 0,0:04:34.02,0:04:39.50,Default,,0000,0000,0000,,we still get "A" names but now we're just\Ngetting up to rank 50. I'm just gonna try Dialogue: 0,0:04:39.50,0:04:44.53,Default,,0000,0000,0000,,a third example here. Alright, now we'll\Ndo an example with OR. Change the code Dialogue: 0,0:04:44.53,0:04:49.38,Default,,0000,0000,0000,,below, so it prints rows where the\Nfollowing is true. Name starts with "X", or Dialogue: 0,0:04:49.38,0:04:54.23,Default,,0000,0000,0000,,the name stars with "Y", or the name stars\Nwith "C". So if I just run, run it right Dialogue: 0,0:04:54.23,0:05:02.72,Default,,0000,0000,0000,,now, the code that's there just does "X". So\NI wanna use OR. And we'll copy this. Dialogue: 0,0:05:02.72,0:05:10.22,Default,,0000,0000,0000,,So by using an OR-test. You make\Nmultiple ways for the overall if-test to Dialogue: 0,0:05:10.22,0:05:15.52,Default,,0000,0000,0000,,be true. It's like, well, the if-test were\Ntrue if this one is true, or if this other Dialogue: 0,0:05:15.52,0:05:20.94,Default,,0000,0000,0000,,thing is true. So it's kind of a widening.\NSo here I'll say, OR row.getField - "Y". Dialogue: 0,0:05:20.94,0:05:27.65,Default,,0000,0000,0000,,So, for the previous run, we only got "X".\NAlright? So I'm gonna run this. Oh, so now Dialogue: 0,0:05:27.65,0:05:33.88,Default,,0000,0000,0000,,we get "X" and "Y". So there's "Yusuf" and\N"Yeritza". Notice that I, my goal Dialogue: 0,0:05:33.88,0:05:38.95,Default,,0000,0000,0000,,ultimately was to show "X" or "Y" or "Z", but I\Nthink it is kinda nice if you get the code Dialogue: 0,0:05:38.95,0:05:43.96,Default,,0000,0000,0000,,into a kind of half built state, but where\Nit makes sense. You know, just try running Dialogue: 0,0:05:43.96,0:05:48.43,Default,,0000,0000,0000,,it and kind of verify, oh that works\Nbefore going on to do the whole thing. Dialogue: 0,0:05:48.43,0:05:53.26,Default,,0000,0000,0000,,That's kind of a classic computer code\Nrule of thumb; don't try and do the entire Dialogue: 0,0:05:53.26,0:05:58.20,Default,,0000,0000,0000,,thing in one step, OR startsWith("Z"). So, I\Nguess partly what I'm showing here is. You Dialogue: 0,0:05:58.20,0:06:02.93,Default,,0000,0000,0000,,can have multiple ORs and multiple ANDs and\Nstring things together. So let's Dialogue: 0,0:06:02.93,0:06:07.30,Default,,0000,0000,0000,,try that, There it goes, Quite a few "Z"\Nnames. So there we have it, "X" or "Y" or" "Z, Dialogue: 0,0:06:07.48,0:06:12.38,Default,,0000,0000,0000,,so this shows the two vertical bars, and\Nthen in this case I have strung together Dialogue: 0,0:06:12.38,0:06:16.69,Default,,0000,0000,0000,,three things. For this class, I will only,\NI'll use either a bunch of things Dialogue: 0,0:06:16.69,0:06:21.30,Default,,0000,0000,0000,,connected with AND or a bunch of things\Nconnected with OR. I won't combine them. Dialogue: 0,0:06:21.30,0:06:25.96,Default,,0000,0000,0000,,Combine them just brings up some other\Ncases that are kind of interesting but I Dialogue: 0,0:06:25.96,0:06:30.55,Default,,0000,0000,0000,,not, I don't really want to get into. They\Ndon't really help a lot. Other thing I Dialogue: 0,0:06:30.55,0:06:33.85,Default,,0000,0000,0000,,should mention about this, alright so I\Nshould just apologize to this. This Dialogue: 0,0:06:33.85,0:06:37.56,Default,,0000,0000,0000,,ampersand business is sort of a historical\Naccident, or the vertical bar business. Dialogue: 0,0:06:37.56,0:06:41.14,Default,,0000,0000,0000,,Language, influencial language chose this\Nin, like the mid'70s. And once one Dialogue: 0,0:06:41.14,0:06:44.81,Default,,0000,0000,0000,,language had chosen this symbol to mean\NOR, some other languages thought, oh, well Dialogue: 0,0:06:44.81,0:06:48.35,Default,,0000,0000,0000,,we should just use that convention. And so\Nit just kinda snowballed, where now, Dialogue: 0,0:06:48.35,0:06:51.88,Default,,0000,0000,0000,,that's a very common convention. So I felt\Nlike, well, it's kind of obscure, but. Dialogue: 0,0:06:51.88,0:06:55.96,Default,,0000,0000,0000,,That's the convention so we should just go\Nahead and learn that one. Alright, So, Dialogue: 0,0:06:55.96,0:06:59.93,Default,,0000,0000,0000,,let's scroll down here a little bit. So\Nactually, what I have set up is just a Dialogue: 0,0:06:59.93,0:07:04.21,Default,,0000,0000,0000,,large number of examples here. And there's\Na show solution button here, so if you Dialogue: 0,0:07:04.21,0:07:08.54,Default,,0000,0000,0000,,want practice or to review these examples\NI've done, you could come back and it's Dialogue: 0,0:07:08.54,0:07:12.67,Default,,0000,0000,0000,,all sorted here. What I'll is I'll just\Ntry the, the first six. So, I'll type in Dialogue: 0,0:07:12.67,0:07:16.54,Default,,0000,0000,0000,,the code for those and I'll leave the\Nothers as kind of extra practice for Dialogue: 0,0:07:16.54,0:07:21.72,Default,,0000,0000,0000,,people who want it. Okay, so the first one\Nsays, name starts with "Ab", or starts with Dialogue: 0,0:07:21.72,0:07:28.18,Default,,0000,0000,0000,,"Ac". So I'll say there's some code here\Nthat we start with already. So it starts Dialogue: 0,0:07:28.18,0:07:39.37,Default,,0000,0000,0000,,with "Ab". And what was it? OR starts with\N"Ac". So this one starts with here, So this Dialogue: 0,0:07:39.37,0:07:48.80,Default,,0000,0000,0000,,should be an OR, Two different or's. Let's\Ntry that one. So we got "A", "Ac" Where's Dialogue: 0,0:07:48.80,0:07:56.30,Default,,0000,0000,0000,,the "Ac" name? Oh. Look I made a bug. I typed\N"Ab" twice. Okay. There we go. Dialogue: 0,0:07:56.30,0:08:02.01,Default,,0000,0000,0000,,Ok, there's an "Ac". That showed that interesting\Nexample of a bug, where sometimes bugs are Dialogue: 0,0:08:02.01,0:08:07.58,Default,,0000,0000,0000,,syntax errors where you hit the run button\Nand it, it just, you know, it, it crashes Dialogue: 0,0:08:07.58,0:08:12.26,Default,,0000,0000,0000,,and you get some red output. But\Nsometimes a bug is just that. I typed Dialogue: 0,0:08:12.26,0:08:16.49,Default,,0000,0000,0000,,something that does mean something to the\Ncomputer, but it's not what I intended. Dialogue: 0,0:08:16.49,0:08:20.46,Default,,0000,0000,0000,,And so then the output is not what I\Nexpected, then I'm a little bit confused. Dialogue: 0,0:08:20.46,0:08:24.48,Default,,0000,0000,0000,,So that's the more higher level kind of\Nbug in this course. It's fairly Dialogue: 0,0:08:24.48,0:08:28.71,Default,,0000,0000,0000,,common with computers. Okay, let's see,\Nnext one. Name starts with "Ab", or Dialogue: 0,0:08:28.71,0:08:33.53,Default,,0000,0000,0000,,"Ac", or "Al". Oh, I see. So this just\Nextends. This just shows that you can have Dialogue: 0,0:08:33.53,0:08:38.36,Default,,0000,0000,0000,,three. So I'll say vertical bar.\NI'll paste this in. So it was "Ac", Dialogue: 0,0:08:38.36,0:08:42.92,Default,,0000,0000,0000,,so "Ab" and "Ac" doesn't give us a lot but\Nwith "Al" you know it's quite a lot. Dialogue: 0,0:08:45.56,0:08:55.58,Default,,0000,0000,0000,,Okay. So the next one was, name starts\Nwith O and ends with A. So I'll say Dialogue: 0,0:08:55.58,0:09:08.88,Default,,0000,0000,0000,,starts, I'll just translate it. Starts\Nwith "O" AND ends with "a". Alright. Let's Dialogue: 0,0:09:08.88,0:09:16.27,Default,,0000,0000,0000,,try that. Oh, there's only one, "Olivia". How\Nbout, starts with O and gender is girl? Dialogue: 0,0:09:16.27,0:09:23.76,Default,,0000,0000,0000,,So, we'll just get gender right here, and\Nthen we test that is not with startsWith Dialogue: 0,0:09:23.76,0:09:30.33,Default,,0000,0000,0000,,endsWith, but just with ==.\NSo, O AND girl. Oh, there's only two. Dialogue: 0,0:09:30.33,0:09:36.40,Default,,0000,0000,0000,,So we get Olive. Okay,\Nname ends with "a" and gender is what? Dialogue: 0,0:09:36.98,0:09:43.97,Default,,0000,0000,0000,,Change this to name.endsWith("a"), and\Nper my previous example, my previous claim, I'll just cut that out. Dialogue: 0,0:09:43.97,0:09:50.97,Default,,0000,0000,0000,,Now it's half built right, name ends with\N"a". But I could run that and sorta verify, Dialogue: 0,0:09:50.97,0:09:58.79,Default,,0000,0000,0000,,all rigt that's working. And then, take\Nyour working thing, and extend it. What Dialogue: 0,0:09:58.79,0:10:06.27,Default,,0000,0000,0000,,did I want? In this case I wanted oh,\Nnames ends with "a" and gender is blank. Dialogue: 0,0:10:06.27,0:10:16.20,Default,,0000,0000,0000,,Okay. Jesus, Lyle. Girl names neither.\NBoy. Oh, well, there's a few, Joshua, Dialogue: 0,0:10:16.20,0:10:23.24,Default,,0000,0000,0000,,Ezra. Okay, I'll do this last one, number\Nsix Rank is less than ten, and gender is Dialogue: 0,0:10:23.24,0:10:29.15,Default,,0000,0000,0000,,girl. So I'll change this to "rank". Instead\Nof endsWith. I'll say, less than or equal to ten. Dialogue: 0,0:10:29.15,0:10:34.18,Default,,0000,0000,0000,,And, so, Now I'm not using startsWith, or\NendsWith for either of these but just Dialogue: 0,0:10:34.18,0:10:39.53,Default,,0000,0000,0000,,notice each one of those is a complete and\Ncorrect test as we discussed before. That Dialogue: 0,0:10:39.53,0:10:44.37,Default,,0000,0000,0000,,one is, and that one is and I'm just\Njoining them from there. So rank is less Dialogue: 0,0:10:44.37,0:10:49.58,Default,,0000,0000,0000,,than ten, and gender in this case is girl.\NLet's try that. So that makes sense. We Dialogue: 0,0:10:49.58,0:10:53.67,Default,,0000,0000,0000,,just get one, two, three, four of them.\NOne through ten girl names. This one's Dialogue: 0,0:10:53.67,0:10:57.97,Default,,0000,0000,0000,,kind of interesting in that this, this I\Nthink has a sensible English translation. Dialogue: 0,0:10:57.97,0:11:02.17,Default,,0000,0000,0000,,What this is, is. What this says is top\Nten girl names, And then, We can phrase Dialogue: 0,0:11:02.17,0:11:06.58,Default,,0000,0000,0000,,that as this AND thing. Where rank is less\Nthan or equal to ten and gender is girl. Or indeed Dialogue: 0,0:11:06.58,0:11:10.93,Default,,0000,0000,0000,,ultimately we can phrase it as code. So\Njust get it down to, to where the computer Dialogue: 0,0:11:10.93,0:11:15.12,Default,,0000,0000,0000,,can actually do it. So there's a few more\Nproblems here and the solutions all Dialogue: 0,0:11:15.12,0:11:19.36,Default,,0000,0000,0000,,available. So this is a good opportunity\Nto come and review what I did or try a Dialogue: 0,0:11:19.36,0:11:23.60,Default,,0000,0000,0000,,little bit of practice before we do the\Nexercises. Cuz these, in some sense, are - Dialogue: 0,0:11:23.60,0:11:28.01,Default,,0000,0000,0000,,computer languages have now gotten big\Nenough that I can really we can have a lot Dialogue: 0,0:11:28.01,0:11:29.78,Default,,0000,0000,0000,,of different [inaudible] alright.