1 00:00:00,000 --> 00:00:11,030 2 00:00:11,030 --> 00:00:12,150 >> JASON HIRSCHHORN: Welcome. 3 00:00:12,150 --> 00:00:14,000 So just a few announcements before we start. 4 00:00:14,000 --> 00:00:16,570 So sections, everyone should have sectioned already. 5 00:00:16,570 --> 00:00:19,474 Sections normally run from Sunday to Tuesday. 6 00:00:19,474 --> 00:00:21,140 So you guys should get your assignments. 7 00:00:21,140 --> 00:00:24,160 And then I think next week you'll be with your actual TFs. 8 00:00:24,160 --> 00:00:27,310 So if you have any questions, or trouble, or you forgot to section. 9 00:00:27,310 --> 00:00:28,820 Some people do that. 10 00:00:28,820 --> 00:00:29,580 Just let us know. 11 00:00:29,580 --> 00:00:30,870 Shoot us an email at heads. 12 00:00:30,870 --> 00:00:33,160 13 00:00:33,160 --> 00:00:34,520 >> Then office hours. 14 00:00:34,520 --> 00:00:36,120 We started office hours last week. 15 00:00:36,120 --> 00:00:37,180 16 00:00:37,180 --> 00:00:38,640 Office hours every week. 17 00:00:38,640 --> 00:00:40,920 Monday is in Leverett 8:00 to 11:00. 18 00:00:40,920 --> 00:00:43,870 Tuesdays in the quad, so Cabot 8:00 to 11:00. 19 00:00:43,870 --> 00:00:45,980 Wednesday, Mather 8:30 to 11:30. 20 00:00:45,980 --> 00:00:48,350 And Thursday Annenberg 8:00 to 11:00. 21 00:00:48,350 --> 00:00:51,810 >> So Scratch, a lot of people don't need office hours 22 00:00:51,810 --> 00:00:54,650 help for Scratch, which is completely fine. 23 00:00:54,650 --> 00:00:56,470 If you do, that's absolutely fine as well. 24 00:00:56,470 --> 00:01:01,060 But in the future, the problem sets, they get much harder. 25 00:01:01,060 --> 00:01:03,090 So this is going to be your friend. 26 00:01:03,090 --> 00:01:04,340 Definitely go to office hours. 27 00:01:04,340 --> 00:01:06,730 Plan on going to office hours. 28 00:01:06,730 --> 00:01:10,279 When you get to problem set four, five, six, seven, 29 00:01:10,279 --> 00:01:11,570 you need to go to office hours. 30 00:01:11,570 --> 00:01:15,030 That's where a lot the help and the work gets done. 31 00:01:15,030 --> 00:01:18,010 >> I think last year, just for example, on Thursday night-- 32 00:01:18,010 --> 00:01:20,090 so I think the problem sets were due on Friday. 33 00:01:20,090 --> 00:01:24,740 So Thursday night, we would have 200, 250 students at office hours. 34 00:01:24,740 --> 00:01:26,904 So definitely make use of these. 35 00:01:26,904 --> 00:01:28,070 These are your best friends. 36 00:01:28,070 --> 00:01:31,050 Like this is where if you're stuck on a problem set, 37 00:01:31,050 --> 00:01:33,020 this is where you'll probably get help. 38 00:01:33,020 --> 00:01:34,100 So office hours. 39 00:01:34,100 --> 00:01:35,130 40 00:01:35,130 --> 00:01:36,990 OK so those are announcements. 41 00:01:36,990 --> 00:01:40,470 Announcements are done, so let's start. 42 00:01:40,470 --> 00:01:41,450 >> OK, the appliance. 43 00:01:41,450 --> 00:01:44,360 Did everybody download the appliance yet? 44 00:01:44,360 --> 00:01:44,860 No. 45 00:01:44,860 --> 00:01:45,699 As in so so. 46 00:01:45,699 --> 00:01:47,157 I kind of downloaded the appliance. 47 00:01:47,157 --> 00:01:48,650 48 00:01:48,650 --> 00:01:52,501 Right so the appliance is new this year, so we're probably 49 00:01:52,501 --> 00:01:53,750 going to have some bugs in it. 50 00:01:53,750 --> 00:01:56,420 So please download it as early as possible. 51 00:01:56,420 --> 00:02:00,120 52 00:02:00,120 --> 00:02:03,390 So problem set one is going to tell you exactly how to download it. 53 00:02:03,390 --> 00:02:05,830 Getting started installing right here. 54 00:02:05,830 --> 00:02:07,042 55 00:02:07,042 --> 00:02:09,250 It's going to tell you how to download the appliance. 56 00:02:09,250 --> 00:02:13,240 >> So definitely download the appliance sooner rather than later. 57 00:02:13,240 --> 00:02:15,290 Instructions are in the P set spec. 58 00:02:15,290 --> 00:02:17,820 59 00:02:17,820 --> 00:02:21,920 So if you wait until Wednesday night, and then you have trouble, 60 00:02:21,920 --> 00:02:24,220 and you send us an email at midnight on Wednesday night 61 00:02:24,220 --> 00:02:26,860 that you can't download the appliance, that's 62 00:02:26,860 --> 00:02:28,365 not a legit reason for an extension. 63 00:02:28,365 --> 00:02:29,390 64 00:02:29,390 --> 00:02:32,540 You need to do it now, and you will have trouble. 65 00:02:32,540 --> 00:02:34,330 I tried to download it last night. 66 00:02:34,330 --> 00:02:36,449 I ran into a little bit of trouble. 67 00:02:36,449 --> 00:02:38,490 If you do run into trouble installing, definitely 68 00:02:38,490 --> 00:02:42,680 hit retry, because I just hit retry a couple times, and eventually it worked, 69 00:02:42,680 --> 00:02:45,910 which doesn't make any sense, but it does. 70 00:02:45,910 --> 00:02:48,950 So definitely retry, but if you come up against a brick wall, 71 00:02:48,950 --> 00:02:52,070 shoot us an email at heads, and we'll be more than happy to help you guys. 72 00:02:52,070 --> 00:02:52,570 What's up? 73 00:02:52,570 --> 00:02:53,861 >> STUDENT: Just a quick question. 74 00:02:53,861 --> 00:02:57,631 If they check style, there's a part that says we didn't include this. 75 00:02:57,631 --> 00:02:58,714 JASON HIRSCHHORN: Not yet. 76 00:02:58,714 --> 00:02:59,880 STUDENT: It says execute it. 77 00:02:59,880 --> 00:03:02,410 How do you execute that to make sure it's in your system? 78 00:03:02,410 --> 00:03:03,660 >> JASON HIRSCHHORN: You're going to run a bash command. 79 00:03:03,660 --> 00:03:05,200 I'll go over that later. 80 00:03:05,200 --> 00:03:06,400 Cool. 81 00:03:06,400 --> 00:03:13,130 So the appliance can be a little bit intimidating, 82 00:03:13,130 --> 00:03:16,700 because you're used to kind of running in graphical user interface. 83 00:03:16,700 --> 00:03:21,257 So Scratch was a graphical user interface, so what do I mean by that? 84 00:03:21,257 --> 00:03:23,090 What I mean is that when you're programming, 85 00:03:23,090 --> 00:03:24,772 you're basically using blocks of code. 86 00:03:24,772 --> 00:03:26,480 You can see the code and stuff like that. 87 00:03:26,480 --> 00:03:30,010 >> The appliance, you're going to be doing things in a command line environment. 88 00:03:30,010 --> 00:03:32,394 And so for the rest of your programming lives, 89 00:03:32,394 --> 00:03:35,060 you're going to be doing things in the command line environment. 90 00:03:35,060 --> 00:03:40,290 So it's good to jump in early and get some experience. 91 00:03:40,290 --> 00:03:43,210 So let's do it. 92 00:03:43,210 --> 00:03:43,860 So that's Rob. 93 00:03:43,860 --> 00:03:46,480 94 00:03:46,480 --> 00:03:48,650 >> OK, so let's just jump into command line stuff. 95 00:03:48,650 --> 00:03:50,480 So this is the appliance. 96 00:03:50,480 --> 00:03:51,810 97 00:03:51,810 --> 00:03:54,729 Can anybody tell me why we use an appliance? 98 00:03:54,729 --> 00:03:55,645 What is the appliance? 99 00:03:55,645 --> 00:03:57,010 100 00:03:57,010 --> 00:03:57,830 Does anybody know? 101 00:03:57,830 --> 00:03:58,538 What's up? 102 00:03:58,538 --> 00:04:02,275 >> STUDENT: It's just a virtual machine that you run your machine so that you 103 00:04:02,275 --> 00:04:06,297 can get over the OS disagreements between Mac and PC. 104 00:04:06,297 --> 00:04:07,380 JASON HIRSCHHORN: Perfect. 105 00:04:07,380 --> 00:04:08,220 STUDENT: It's a universal template. 106 00:04:08,220 --> 00:04:09,420 JASON HIRSCHHORN: Yeah, it's like a universal template. 107 00:04:09,420 --> 00:04:10,045 That's perfect. 108 00:04:10,045 --> 00:04:11,740 So yeah, it's a virtual machine. 109 00:04:11,740 --> 00:04:13,660 So it's basically an operating system. 110 00:04:13,660 --> 00:04:14,920 This is an operating system. 111 00:04:14,920 --> 00:04:18,160 This is equivalent to your Mac, or you PC, or your Linux. 112 00:04:18,160 --> 00:04:19,217 This is the exact same. 113 00:04:19,217 --> 00:04:20,550 And so you can do similar stuff. 114 00:04:20,550 --> 00:04:23,370 If you wanted to, you could go online for example. 115 00:04:23,370 --> 00:04:25,920 You can't really see it, but right here, Google Chrome. 116 00:04:25,920 --> 00:04:27,294 You can go online if you want to. 117 00:04:27,294 --> 00:04:28,754 This is an operating system. 118 00:04:28,754 --> 00:04:31,920 And the reason we do that is because it's much easier when we're handing out 119 00:04:31,920 --> 00:04:33,216 instructions and everything. 120 00:04:33,216 --> 00:04:35,715 If it's just a uniform environment, it's much easier for us, 121 00:04:35,715 --> 00:04:37,310 and it's much easier for you. 122 00:04:37,310 --> 00:04:41,380 You're not going to run into it run into any idiosyncrasies 123 00:04:41,380 --> 00:04:42,380 when you're programming. 124 00:04:42,380 --> 00:04:44,510 We know exactly what you're going to run into. 125 00:04:44,510 --> 00:04:47,120 So the appliance is here. 126 00:04:47,120 --> 00:04:50,172 >> So when you're starting programming, you're 127 00:04:50,172 --> 00:04:51,880 going to go down to the left hand corner. 128 00:04:51,880 --> 00:04:53,439 There's a little box. 129 00:04:53,439 --> 00:04:54,480 You're going to click it. 130 00:04:54,480 --> 00:04:55,760 This is your terminal window. 131 00:04:55,760 --> 00:04:57,680 132 00:04:57,680 --> 00:05:01,980 So this is where you're going to be a lot of the semester. 133 00:05:01,980 --> 00:05:03,837 So let me zoom in a little bit. 134 00:05:03,837 --> 00:05:07,820 135 00:05:07,820 --> 00:05:11,630 >> OK, so getting around a terminal window is a little bit different. 136 00:05:11,630 --> 00:05:13,610 First, there's no icons. 137 00:05:13,610 --> 00:05:15,780 I can't click anything. 138 00:05:15,780 --> 00:05:17,170 There's nothing to click. 139 00:05:17,170 --> 00:05:21,390 So you have to figure out a way to figure out where you are, what's here, 140 00:05:21,390 --> 00:05:22,830 and how to move around. 141 00:05:22,830 --> 00:05:29,630 >> So the two most useful commands probably are ls-- so what do you think ls does? 142 00:05:29,630 --> 00:05:30,771 >> STUDENT: List. 143 00:05:30,771 --> 00:05:32,020 JASON HIRSCHHORN: Lists, yeah. 144 00:05:32,020 --> 00:05:33,936 It just lists algorithms within the directory. 145 00:05:33,936 --> 00:05:35,190 And then cd. 146 00:05:35,190 --> 00:05:39,280 So let's say I wanted to cd CS50, what did that do? 147 00:05:39,280 --> 00:05:40,230 148 00:05:40,230 --> 00:05:40,730 Yeah? 149 00:05:40,730 --> 00:05:42,064 >> STUDENT: Changes your directory. 150 00:05:42,064 --> 00:05:43,396 JASON HIRSCHHORN: Perfect, yeah. 151 00:05:43,396 --> 00:05:44,780 It just changes the directory. 152 00:05:44,780 --> 00:05:46,250 So let's go back. 153 00:05:46,250 --> 00:05:47,440 So how do I go back? 154 00:05:47,440 --> 00:05:50,590 So let's say I wanted to go back to the previous directory. 155 00:05:50,590 --> 00:05:53,181 156 00:05:53,181 --> 00:05:53,680 Yeah sure. 157 00:05:53,680 --> 00:05:55,847 >> STUDENT: I think you write cd just without anything. 158 00:05:55,847 --> 00:05:57,263 JASON HIRSCHHORN: You can do that. 159 00:05:57,263 --> 00:05:57,800 So perfect. 160 00:05:57,800 --> 00:05:59,950 So if I write cd, this is actually going to pop me 161 00:05:59,950 --> 00:06:01,800 back up to the home directory. 162 00:06:01,800 --> 00:06:04,510 So you see this tilde, that's going to pop me 163 00:06:04,510 --> 00:06:06,240 way back up to where the tilde is. 164 00:06:06,240 --> 00:06:07,410 So it's going to pop me up back to the home directory. 165 00:06:07,410 --> 00:06:09,076 But let's say I did something like this. 166 00:06:09,076 --> 00:06:10,600 Let's say cd CS50. 167 00:06:10,600 --> 00:06:11,800 168 00:06:11,800 --> 00:06:13,060 ls again. 169 00:06:13,060 --> 00:06:15,180 I've got other stuff. cd super section. 170 00:06:15,180 --> 00:06:17,600 171 00:06:17,600 --> 00:06:18,920 cd file, so I'm going deep. 172 00:06:18,920 --> 00:06:20,250 173 00:06:20,250 --> 00:06:23,590 And then let's say I want to just pop back up to the top. 174 00:06:23,590 --> 00:06:24,090 cd. 175 00:06:24,090 --> 00:06:24,784 176 00:06:24,784 --> 00:06:26,200 Let's say I don't want to do that. 177 00:06:26,200 --> 00:06:29,590 Let's say I just want to pop back up to the directory that was right above me. 178 00:06:29,590 --> 00:06:30,350 How do I do that? 179 00:06:30,350 --> 00:06:33,180 So let's say cd CS50. 180 00:06:33,180 --> 00:06:36,050 181 00:06:36,050 --> 00:06:38,090 cd supersection. 182 00:06:38,090 --> 00:06:39,370 So let's I'm here. 183 00:06:39,370 --> 00:06:42,012 Let's say I just want to pop up one time. 184 00:06:42,012 --> 00:06:42,720 How do I do that? 185 00:06:42,720 --> 00:06:44,170 186 00:06:44,170 --> 00:06:45,120 Yeah, what's up? 187 00:06:45,120 --> 00:06:47,560 >> STUDENT: You just type cd supersection again. 188 00:06:47,560 --> 00:06:49,060 >> JASON HIRSCHHORN: You could do that. 189 00:06:49,060 --> 00:06:50,730 Well I'm in supersection. 190 00:06:50,730 --> 00:06:51,970 >> STUDENT: Oh, the one before. 191 00:06:51,970 --> 00:06:53,845 >> JASON HIRSCHHORN: Yeah, so you could do that. 192 00:06:53,845 --> 00:06:55,620 You do cd ~CS50. 193 00:06:55,620 --> 00:06:57,410 194 00:06:57,410 --> 00:07:01,770 So if you look here, this is your path right here. 195 00:07:01,770 --> 00:07:03,890 196 00:07:03,890 --> 00:07:05,140 That's your path. 197 00:07:05,140 --> 00:07:07,185 So you could seriously just go cd ~/CS50. 198 00:07:07,185 --> 00:07:11,170 199 00:07:11,170 --> 00:07:12,399 Boom, you're there. 200 00:07:12,399 --> 00:07:13,940 What's an easier way to do it though? 201 00:07:13,940 --> 00:07:16,650 That was perfectly correct, but what's a slightly easier way 202 00:07:16,650 --> 00:07:17,880 to do it, because a lot of times you're going 203 00:07:17,880 --> 00:07:20,510 to be jumping in directories, jumping out of directories. 204 00:07:20,510 --> 00:07:21,790 So let's go back. 205 00:07:21,790 --> 00:07:22,510 cd supersection. 206 00:07:22,510 --> 00:07:23,349 207 00:07:23,349 --> 00:07:25,140 So let's say I want to get back real quick. 208 00:07:25,140 --> 00:07:28,689 You can do something like cd dot dot. 209 00:07:28,689 --> 00:07:30,480 That's going to pop you back up real quick. 210 00:07:30,480 --> 00:07:31,570 So cd supersection. 211 00:07:31,570 --> 00:07:36,010 212 00:07:36,010 --> 00:07:37,440 cd files. 213 00:07:37,440 --> 00:07:38,890 Let's say I'm here. 214 00:07:38,890 --> 00:07:42,790 By the way, clear is good, because my window was getting a little bit messy. 215 00:07:42,790 --> 00:07:46,190 So ls, so I don't want to be here anymore. cd dot dot. 216 00:07:46,190 --> 00:07:47,072 Take me one up. 217 00:07:47,072 --> 00:07:49,130 Cd dot dot takes me one up. 218 00:07:49,130 --> 00:07:50,600 Cd dot dot and back to my home. 219 00:07:50,600 --> 00:07:53,820 220 00:07:53,820 --> 00:07:55,180 >> OK, so cd, ls. 221 00:07:55,180 --> 00:07:57,263 Probably the most important things, because you're 222 00:07:57,263 --> 00:07:58,880 going to need to know where you are. 223 00:07:58,880 --> 00:08:00,790 ls is going to tell you where you are, and cd 224 00:08:00,790 --> 00:08:02,610 is how you're going to jump around. 225 00:08:02,610 --> 00:08:04,300 >> You can also do some other cool stuff. 226 00:08:04,300 --> 00:08:05,470 227 00:08:05,470 --> 00:08:07,190 So for example ls. 228 00:08:07,190 --> 00:08:09,610 ls is just going to show you the directories in your file. 229 00:08:09,610 --> 00:08:10,780 It's also going to show you the files. 230 00:08:10,780 --> 00:08:12,680 But it's just going to show you what's there. 231 00:08:12,680 --> 00:08:14,638 >> If you wanted something a little bit more cool, 232 00:08:14,638 --> 00:08:19,210 and you're going to actually do this in a couple weeks. ls dash l. 233 00:08:19,210 --> 00:08:20,995 That prints out a little more information. 234 00:08:20,995 --> 00:08:22,360 235 00:08:22,360 --> 00:08:28,170 Can anybody guess on the left hand side the drwx, rwx and stuff like that. 236 00:08:28,170 --> 00:08:30,330 Does anybody have an idea what that might mean? 237 00:08:30,330 --> 00:08:31,290 >> STUDENT: Permissions. 238 00:08:31,290 --> 00:08:32,080 >> JASON HIRSCHHORN: Yeah, perfect. 239 00:08:32,080 --> 00:08:32,580 Permissions. 240 00:08:32,580 --> 00:08:33,742 241 00:08:33,742 --> 00:08:35,450 So you're going to have to deal with this 242 00:08:35,450 --> 00:08:37,610 when you do web programming later on. 243 00:08:37,610 --> 00:08:40,320 If you've ever gone online, and you've clicked on an image 244 00:08:40,320 --> 00:08:42,821 or clicked on a field, and it said permission-- 245 00:08:42,821 --> 00:08:45,820 like permission not allowed, or like permission not granted or whatever, 246 00:08:45,820 --> 00:08:47,990 that's because when they're programming, they 247 00:08:47,990 --> 00:08:50,420 haven't set these permissions to let you do that. 248 00:08:50,420 --> 00:08:51,990 So where that comes from. 249 00:08:51,990 --> 00:08:53,770 250 00:08:53,770 --> 00:08:56,700 >> OK, so that's cool. 251 00:08:56,700 --> 00:08:58,580 So we jumped around. 252 00:08:58,580 --> 00:09:00,310 We can look at stuff in our directory. 253 00:09:00,310 --> 00:09:01,560 But how do we make stuff? 254 00:09:01,560 --> 00:09:02,730 255 00:09:02,730 --> 00:09:04,186 I've got directories here. 256 00:09:04,186 --> 00:09:04,810 That's awesome. 257 00:09:04,810 --> 00:09:06,080 How do I make a new directory? 258 00:09:06,080 --> 00:09:07,019 259 00:09:07,019 --> 00:09:09,060 Say I want to make a new directory for right now. 260 00:09:09,060 --> 00:09:11,070 261 00:09:11,070 --> 00:09:13,470 You can do something like this, mkdir. 262 00:09:13,470 --> 00:09:16,160 263 00:09:16,160 --> 00:09:17,244 So make directory. 264 00:09:17,244 --> 00:09:19,035 So what do you want to call this directory? 265 00:09:19,035 --> 00:09:21,454 266 00:09:21,454 --> 00:09:22,162 STUDENT: Awesome. 267 00:09:22,162 --> 00:09:24,107 268 00:09:24,107 --> 00:09:25,190 JASON HIRSCHHORN: Awesome. 269 00:09:25,190 --> 00:09:25,690 I love it. 270 00:09:25,690 --> 00:09:26,650 271 00:09:26,650 --> 00:09:27,790 Make directory awesome. 272 00:09:27,790 --> 00:09:28,802 273 00:09:28,802 --> 00:09:29,510 And there you go. 274 00:09:29,510 --> 00:09:30,809 So we need a list. 275 00:09:30,809 --> 00:09:31,850 You have a new directory. 276 00:09:31,850 --> 00:09:33,180 And you can tell it's a directory in your appliance 277 00:09:33,180 --> 00:09:34,850 because it's got this color, right? 278 00:09:34,850 --> 00:09:37,970 So it's like a bluish purple or whatever. 279 00:09:37,970 --> 00:09:39,260 280 00:09:39,260 --> 00:09:40,020 So let's change. 281 00:09:40,020 --> 00:09:40,860 Let's change directory. 282 00:09:40,860 --> 00:09:42,609 Let's go into directory-- yeah, what's up? 283 00:09:42,609 --> 00:09:46,114 STUDENT: Is there a list of all these [INAUDIBLE] online? 284 00:09:46,114 --> 00:09:48,780 JASON HIRSCHHORN: Yeah, I'll put them up on-- we'll have slides. 285 00:09:48,780 --> 00:09:49,407 It'll be a PDF. 286 00:09:49,407 --> 00:09:50,740 We'll put them up for everybody. 287 00:09:50,740 --> 00:09:53,170 Yeah, sorry it's a lot of commands. 288 00:09:53,170 --> 00:09:56,092 if you want me to slow down, or go back, or anything like that, 289 00:09:56,092 --> 00:09:57,050 definitely let me know. 290 00:09:57,050 --> 00:09:59,510 It's a lot to absorb right away. 291 00:09:59,510 --> 00:10:00,059 What's up? 292 00:10:00,059 --> 00:10:02,100 STUDENT: Can I ask a potentially stupid question? 293 00:10:02,100 --> 00:10:03,240 JASON HIRSCHHORN: There's no stupid questions. 294 00:10:03,240 --> 00:10:04,031 STUDENT: There are. 295 00:10:04,031 --> 00:10:06,462 296 00:10:06,462 --> 00:10:09,384 A directory is for just looking at information where you store it. 297 00:10:09,384 --> 00:10:09,871 >> JASON HIRSCHHORN: Yeah. 298 00:10:09,871 --> 00:10:11,829 >> STUDENT: Is that essentially what you're doing? 299 00:10:11,829 --> 00:10:14,741 So when we make something, hello world or whatever, 300 00:10:14,741 --> 00:10:16,202 it's stored in the directory, yes? 301 00:10:16,202 --> 00:10:16,689 >> JASON HIRSCHHORN: Yeah. 302 00:10:16,689 --> 00:10:18,637 >> STUDENT: Is that true for everything. 303 00:10:18,637 --> 00:10:20,340 Everything is stored in the directory. 304 00:10:20,340 --> 00:10:20,680 >> JASON HIRSCHHORN: Yeah. 305 00:10:20,680 --> 00:10:22,490 Whenever you make it, whatever directory you're in, 306 00:10:22,490 --> 00:10:24,615 it's going to basically store it in that directory. 307 00:10:24,615 --> 00:10:27,680 STUDENT: And when we're calling it, we're calling it from the directory. 308 00:10:27,680 --> 00:10:30,013 >> JASON HIRSCHHORN: Yeah, so the directory is where it es. 309 00:10:30,013 --> 00:10:32,910 So it's kind of like if you have a new folder on your desktop 310 00:10:32,910 --> 00:10:36,530 and then you write a text file, put it in that folder, 311 00:10:36,530 --> 00:10:38,160 that file is in that folder. 312 00:10:38,160 --> 00:10:39,690 Does that make sense? 313 00:10:39,690 --> 00:10:40,570 >> STUDENT: Yeah. 314 00:10:40,570 --> 00:10:41,646 >> JASON HIRSCHHORN: Yeah, what's up? 315 00:10:41,646 --> 00:10:43,390 >> STUDENT: Can I just ask you to make it a little bit bigger? 316 00:10:43,390 --> 00:10:43,940 >> JASON HIRSCHHORN: Oh, yeah. 317 00:10:43,940 --> 00:10:44,439 Sorry. 318 00:10:44,439 --> 00:10:45,730 319 00:10:45,730 --> 00:10:46,732 The projector is so bad. 320 00:10:46,732 --> 00:10:48,440 We had so much trouble with this earlier. 321 00:10:48,440 --> 00:10:52,240 322 00:10:52,240 --> 00:10:53,872 Is that better? 323 00:10:53,872 --> 00:10:55,617 Is that too big? 324 00:10:55,617 --> 00:10:57,080 >> STUDENT: No, no it's not. 325 00:10:57,080 --> 00:10:58,440 >> JASON HIRSCHHORN: No, it's not. 326 00:10:58,440 --> 00:10:59,170 Is it too small? 327 00:10:59,170 --> 00:11:00,480 328 00:11:00,480 --> 00:11:01,030 What's up? 329 00:11:01,030 --> 00:11:03,760 >> STUDENT: I'm sorry, what's the command for clearing? 330 00:11:03,760 --> 00:11:04,926 >> JASON HIRSCHHORN: Oh, clear. 331 00:11:04,926 --> 00:11:07,085 332 00:11:07,085 --> 00:11:10,230 If you want to clear, just type clear. clear enter. 333 00:11:10,230 --> 00:11:12,104 334 00:11:12,104 --> 00:11:14,020 On the last appliance, what it basically does, 335 00:11:14,020 --> 00:11:17,060 it doesn't clear your information, it just kind of shift everything 336 00:11:17,060 --> 00:11:18,350 down one screen. 337 00:11:18,350 --> 00:11:21,200 So if you typed clear-- for example let's say I'm scrolling up. 338 00:11:21,200 --> 00:11:21,900 I can scroll up. 339 00:11:21,900 --> 00:11:22,941 This is everything I did. 340 00:11:22,941 --> 00:11:23,750 341 00:11:23,750 --> 00:11:29,500 But if I type clear, and then I scroll up, here's my stuff. 342 00:11:29,500 --> 00:11:32,600 So it's not erasing it, it's just basically giving you a new frame. 343 00:11:32,600 --> 00:11:33,983 344 00:11:33,983 --> 00:11:35,940 >> STUDENT: How do you [INAUDIBLE] a directory? 345 00:11:35,940 --> 00:11:37,428 >> JASON HIRSCHHORN: We'll get there. 346 00:11:37,428 --> 00:11:39,536 >> [LAUGHTER] 347 00:11:39,536 --> 00:11:40,160 Slow your roll. 348 00:11:40,160 --> 00:11:41,720 349 00:11:41,720 --> 00:11:42,370 All right. 350 00:11:42,370 --> 00:11:45,590 OK, so so we're in a directory right now. 351 00:11:45,590 --> 00:11:48,360 352 00:11:48,360 --> 00:11:52,700 So David, I think in lecture he did some cool stuff. 353 00:11:52,700 --> 00:11:53,875 So let's write a program. 354 00:11:53,875 --> 00:11:56,000 355 00:11:56,000 --> 00:11:58,540 So you can do that a number of different ways. 356 00:11:58,540 --> 00:12:00,040 You can use any kind of text editor. 357 00:12:00,040 --> 00:12:03,090 You can use Nano, you can use Vim, Emacs. 358 00:12:03,090 --> 00:12:05,110 Those are slightly more complicated. 359 00:12:05,110 --> 00:12:06,822 360 00:12:06,822 --> 00:12:09,030 Or you can use something in here that's called gedit. 361 00:12:09,030 --> 00:12:12,716 362 00:12:12,716 --> 00:12:13,215 Sorry. 363 00:12:13,215 --> 00:12:18,590 364 00:12:18,590 --> 00:12:19,480 gedit is not happy. 365 00:12:19,480 --> 00:12:21,870 366 00:12:21,870 --> 00:12:27,870 So gedit is basically just a text editor. 367 00:12:27,870 --> 00:12:30,780 Just like I text edit word processor or something like that. 368 00:12:30,780 --> 00:12:33,260 So it's got a nice interface just like this. 369 00:12:33,260 --> 00:12:36,340 So you do something like that. 370 00:12:36,340 --> 00:12:39,190 So actually let me give it name because I never did that. 371 00:12:39,190 --> 00:12:40,620 372 00:12:40,620 --> 00:12:43,170 >> So what do you want to name our first program? 373 00:12:43,170 --> 00:12:44,566 It's just going to say hi. 374 00:12:44,566 --> 00:12:45,441 >> STUDENT: [INAUDIBLE]. 375 00:12:45,441 --> 00:12:46,470 376 00:12:46,470 --> 00:12:48,180 >> JASON HIRSCHHORN: You lack imagination. 377 00:12:48,180 --> 00:12:49,615 OK, gedit. 378 00:12:49,615 --> 00:12:50,115 Hi. 379 00:12:50,115 --> 00:12:51,166 380 00:12:51,166 --> 00:12:52,040 I'm going to do .txt. 381 00:12:52,040 --> 00:12:54,470 382 00:12:54,470 --> 00:12:55,680 OK, so here it is. 383 00:12:55,680 --> 00:12:57,820 So let's write a program. 384 00:12:57,820 --> 00:13:01,280 So I think you saw this in lecture. 385 00:13:01,280 --> 00:13:02,380 You need a main function. 386 00:13:02,380 --> 00:13:04,690 387 00:13:04,690 --> 00:13:05,190 Boop. 388 00:13:05,190 --> 00:13:06,910 389 00:13:06,910 --> 00:13:08,280 So this is just a main function. 390 00:13:08,280 --> 00:13:10,550 391 00:13:10,550 --> 00:13:11,050 Bigger? 392 00:13:11,050 --> 00:13:11,550 Yeah, sorry. 393 00:13:11,550 --> 00:13:16,690 394 00:13:16,690 --> 00:13:19,102 OK so you need a main function. 395 00:13:19,102 --> 00:13:20,810 I think I'm jumping the gun a little bit, 396 00:13:20,810 --> 00:13:23,750 but it's never bad to get used to this kind of stuff. 397 00:13:23,750 --> 00:13:25,680 >> So a main function, every C program you're 398 00:13:25,680 --> 00:13:28,555 going to write for the rest of this course will have a main function. 399 00:13:28,555 --> 00:13:29,004 400 00:13:29,004 --> 00:13:29,920 Does anybody know why? 401 00:13:29,920 --> 00:13:31,231 402 00:13:31,231 --> 00:13:32,105 What's up? 403 00:13:32,105 --> 00:13:32,980 >> STUDENT: Start. 404 00:13:32,980 --> 00:13:35,020 >> JASON HIRSCHHORN: Exactly, so it tells your program where to start. 405 00:13:35,020 --> 00:13:38,169 So if you don't have a main function, and you compile this and stuff, 406 00:13:38,169 --> 00:13:39,710 it's not going to know were to start. 407 00:13:39,710 --> 00:13:41,810 Main is always where it starts. 408 00:13:41,810 --> 00:13:46,910 So you have a main function, and then does anybody remember how to print? 409 00:13:46,910 --> 00:13:47,699 >> STUDENT: printf. 410 00:13:47,699 --> 00:13:48,990 JASON HIRSCHHORN: Yeah, printf. 411 00:13:48,990 --> 00:13:50,280 412 00:13:50,280 --> 00:13:52,794 printf hi. 413 00:13:52,794 --> 00:13:55,080 414 00:13:55,080 --> 00:14:02,450 OK, now I have set you guys up to fail, but will this compile. 415 00:14:02,450 --> 00:14:03,290 >> STUDENT: No. 416 00:14:03,290 --> 00:14:03,520 >> JASON HIRSCHHORN: Why? 417 00:14:03,520 --> 00:14:04,830 There's multiple reasons why. 418 00:14:04,830 --> 00:14:06,460 419 00:14:06,460 --> 00:14:07,300 Sure. 420 00:14:07,300 --> 00:14:09,700 >> STUDENT: It doesn't have the standard [INAUDIBLE]. 421 00:14:09,700 --> 00:14:10,783 >> JASON HIRSCHHORN: Perfect. 422 00:14:10,783 --> 00:14:12,122 So what's this called up here? 423 00:14:12,122 --> 00:14:13,540 >> STUDENT: [INAUDIBLE] 424 00:14:13,540 --> 00:14:14,540 >> JASON HIRSCHHORN: It's a header file, right? 425 00:14:14,540 --> 00:14:15,331 It's a header file. 426 00:14:15,331 --> 00:14:16,460 And you're exactly right. 427 00:14:16,460 --> 00:14:17,376 Both of you are right. 428 00:14:17,376 --> 00:14:21,340 So to include that, I just do pound include standard input output .h. 429 00:14:21,340 --> 00:14:22,787 430 00:14:22,787 --> 00:14:23,620 Am I good to go now? 431 00:14:23,620 --> 00:14:27,570 432 00:14:27,570 --> 00:14:28,520 Would this compile? 433 00:14:28,520 --> 00:14:29,263 >> STUDENT: No. 434 00:14:29,263 --> 00:14:30,346 JASON HIRSCHHORN: Why not? 435 00:14:30,346 --> 00:14:32,417 STUDENT: It's a [INAUDIBLE] text. 436 00:14:32,417 --> 00:14:33,750 JASON HIRSCHHORN: Yeah, awesome. 437 00:14:33,750 --> 00:14:34,900 438 00:14:34,900 --> 00:14:36,420 So I just made it. 439 00:14:36,420 --> 00:14:46,130 So I saved it, but gedit hi.txt. 440 00:14:46,130 --> 00:14:47,170 441 00:14:47,170 --> 00:14:50,080 So now if I do ls, here it is. 442 00:14:50,080 --> 00:14:50,580 Right here. 443 00:14:50,580 --> 00:14:51,716 Oh, it's not in awesome. 444 00:14:51,716 --> 00:14:52,590 I must have gone out. 445 00:14:52,590 --> 00:14:53,740 446 00:14:53,740 --> 00:14:54,620 Oh, perfect. 447 00:14:54,620 --> 00:14:56,200 How do we put this in awesome? 448 00:14:56,200 --> 00:14:59,150 So I don't want it here in my home directory with everything else. 449 00:14:59,150 --> 00:15:00,832 I want to put it in the folder. 450 00:15:00,832 --> 00:15:01,540 How do I do that? 451 00:15:01,540 --> 00:15:09,530 452 00:15:09,530 --> 00:15:10,210 >> Not too hard. 453 00:15:10,210 --> 00:15:13,566 454 00:15:13,566 --> 00:15:14,065 Move. 455 00:15:14,065 --> 00:15:16,410 456 00:15:16,410 --> 00:15:18,700 So we've already learned ls, list. 457 00:15:18,700 --> 00:15:19,900 cd to change directories. 458 00:15:19,900 --> 00:15:21,739 cd dot dot to bump out of directories. 459 00:15:21,739 --> 00:15:23,780 And now we're going to start moving around files. 460 00:15:23,780 --> 00:15:30,210 So to move just move hi.txt, and I'm going to put it in awesome. 461 00:15:30,210 --> 00:15:31,270 462 00:15:31,270 --> 00:15:32,310 >> Just be careful. 463 00:15:32,310 --> 00:15:34,976 Whenever you're writing in the command line, everything matters. 464 00:15:34,976 --> 00:15:37,020 So uppercase matters. 465 00:15:37,020 --> 00:15:40,440 If I had done lowercase a, it's not going to know what's going on. 466 00:15:40,440 --> 00:15:42,840 So everything matters to be very specific. 467 00:15:42,840 --> 00:15:45,120 >> So run that ls. 468 00:15:45,120 --> 00:15:46,310 It's no longer here. 469 00:15:46,310 --> 00:15:48,040 Let's change directory into awesome. 470 00:15:48,040 --> 00:15:49,380 471 00:15:49,380 --> 00:15:49,880 ls. 472 00:15:49,880 --> 00:15:50,782 473 00:15:50,782 --> 00:15:51,490 Boom, it's there. 474 00:15:51,490 --> 00:15:53,940 And somebody mentioned why this would not compile. 475 00:15:53,940 --> 00:15:55,410 Why is not going to compile again? 476 00:15:55,410 --> 00:15:56,891 477 00:15:56,891 --> 00:15:57,390 Yeah? 478 00:15:57,390 --> 00:15:58,690 >> STUDENT: It's not in a .c. 479 00:15:58,690 --> 00:15:59,060 >> JASON HIRSCHHORN: Perfect. 480 00:15:59,060 --> 00:16:01,686 It's not a .c, s so how am I going to rename it to a .c? 481 00:16:01,686 --> 00:16:03,120 What's an easy way to do it? 482 00:16:03,120 --> 00:16:05,200 483 00:16:05,200 --> 00:16:06,720 Let's use the command we just did. 484 00:16:06,720 --> 00:16:13,860 So we're just going to move hi.txt to hi.c. 485 00:16:13,860 --> 00:16:15,160 486 00:16:15,160 --> 00:16:16,710 ls hi.c. 487 00:16:16,710 --> 00:16:19,990 And then just for fun, let's just jump into this real quick. 488 00:16:19,990 --> 00:16:24,291 489 00:16:24,291 --> 00:16:24,790 hi.c. 490 00:16:24,790 --> 00:16:26,290 491 00:16:26,290 --> 00:16:28,400 You'll notice it's nice and colorful. 492 00:16:28,400 --> 00:16:30,490 493 00:16:30,490 --> 00:16:33,690 So these are just kind of helpful colors when you're programming. 494 00:16:33,690 --> 00:16:36,350 So the int and the void, those are data types. 495 00:16:36,350 --> 00:16:38,080 We'll go over those in a second. 496 00:16:38,080 --> 00:16:39,650 Hi is a string. 497 00:16:39,650 --> 00:16:40,890 But useful colors. 498 00:16:40,890 --> 00:16:44,790 So if you ever accidentally choose the wrong extension, 499 00:16:44,790 --> 00:16:46,150 you should have these colors. 500 00:16:46,150 --> 00:16:46,650 What's up? 501 00:16:46,650 --> 00:16:50,772 >> STUDENT: How can I copy into a file [INAUDIBLE] into another file? 502 00:16:50,772 --> 00:16:52,980 JASON HIRSCHHORN: Oh, I'm going to show you that too. 503 00:16:52,980 --> 00:16:55,070 So copy remove are on the dock. 504 00:16:55,070 --> 00:16:58,300 505 00:16:58,300 --> 00:16:59,070 Let's make this. 506 00:16:59,070 --> 00:17:00,310 Make sure it works. 507 00:17:00,310 --> 00:17:00,960 Make hi. 508 00:17:00,960 --> 00:17:02,430 509 00:17:02,430 --> 00:17:03,610 Works, run it. 510 00:17:03,610 --> 00:17:08,484 So ./hi awesome. 511 00:17:08,484 --> 00:17:09,609 That is your first program. 512 00:17:09,609 --> 00:17:10,800 Let me make it bigger. 513 00:17:10,800 --> 00:17:15,130 514 00:17:15,130 --> 00:17:16,833 So a really good-- Yeah, what's up? 515 00:17:16,833 --> 00:17:18,833 STUDENT: Why would it be that when I take gedit, 516 00:17:18,833 --> 00:17:21,809 it doesn't give me another line for gedit hi.txt? 517 00:17:21,809 --> 00:17:23,793 518 00:17:23,793 --> 00:17:25,690 It just puts the cursor to a line. 519 00:17:25,690 --> 00:17:26,273 STUDENT: Yeah. 520 00:17:26,273 --> 00:17:27,265 The [INAUDIBLE]. 521 00:17:27,265 --> 00:17:29,520 522 00:17:29,520 --> 00:17:31,510 >> JASON HIRSCHHORN: Wait, so say that again. 523 00:17:31,510 --> 00:17:35,279 >> STUDENT: When I type gedit, the first time, the first line-- 524 00:17:35,279 --> 00:17:37,070 JASON HIRSCHHORN: Up there at the very top? 525 00:17:37,070 --> 00:17:39,800 STUDENT: Has no J Harvard appliance, and the cursor 526 00:17:39,800 --> 00:17:41,237 is just all the way to the left. 527 00:17:41,237 --> 00:17:42,986 JASON HIRSCHHORN: All the way to the left? 528 00:17:42,986 --> 00:17:43,569 STUDENT: Yeah. 529 00:17:43,569 --> 00:17:44,810 Does anyone else have that? 530 00:17:44,810 --> 00:17:46,920 >> JASON HIRSCHHORN: Oh, well J Harvard is just like the username. 531 00:17:46,920 --> 00:17:48,770 So that's just the standard username. 532 00:17:48,770 --> 00:17:49,978 >> STUDENT: It stops responding. 533 00:17:49,978 --> 00:17:51,090 534 00:17:51,090 --> 00:17:52,840 JASON HIRSCHHORN: Oh, it stops responding. 535 00:17:52,840 --> 00:17:55,570 OK, so what you have to do is you have to close out of gedit. 536 00:17:55,570 --> 00:17:58,360 So close out of gedit, and it should return. 537 00:17:58,360 --> 00:18:00,726 So is gedit open on your appliance right now? 538 00:18:00,726 --> 00:18:02,636 539 00:18:02,636 --> 00:18:05,510 If you exit out of it, it should return and you should be good to go. 540 00:18:05,510 --> 00:18:08,257 541 00:18:08,257 --> 00:18:08,840 Did that work? 542 00:18:08,840 --> 00:18:10,824 543 00:18:10,824 --> 00:18:13,850 >> STUDENT: So did you use the gedit command to open-- 544 00:18:13,850 --> 00:18:16,350 JASON HIRSCHHORN: No, the first gedit command was a mistake. 545 00:18:16,350 --> 00:18:17,930 546 00:18:17,930 --> 00:18:19,860 The first gedit command, I to do gedit hi.txt. 547 00:18:19,860 --> 00:18:21,170 548 00:18:21,170 --> 00:18:24,240 So I give it a name, so gedit hi.txt. 549 00:18:24,240 --> 00:18:27,070 hi.txt is the name of the file. 550 00:18:27,070 --> 00:18:28,890 The first one was just a mistake, and then 551 00:18:28,890 --> 00:18:30,450 I quickly closed out of the program. 552 00:18:30,450 --> 00:18:36,737 So the question was if I do gedit, I'm not 553 00:18:36,737 --> 00:18:39,320 going to be able to really do anything else in my command line 554 00:18:39,320 --> 00:18:42,390 until I close that gedit, so I think that's what they ran into. 555 00:18:42,390 --> 00:18:43,689 So close the gedit. 556 00:18:43,689 --> 00:18:45,730 It'll return out of that program, and then you'll 557 00:18:45,730 --> 00:18:49,090 be able to actually type in the command line again. 558 00:18:49,090 --> 00:18:50,290 559 00:18:50,290 --> 00:18:52,198 Is that good? 560 00:18:52,198 --> 00:18:52,698 Dope. 561 00:18:52,698 --> 00:18:57,715 562 00:18:57,715 --> 00:19:00,410 So just make sure to close it if you run into trouble. 563 00:19:00,410 --> 00:19:01,860 564 00:19:01,860 --> 00:19:04,465 >> OK, so a really good question a second ago was copying. 565 00:19:04,465 --> 00:19:06,790 566 00:19:06,790 --> 00:19:08,440 So now I have hi.c. 567 00:19:08,440 --> 00:19:09,890 But let's say I want to change it. 568 00:19:09,890 --> 00:19:11,630 I want it to be slightly better. 569 00:19:11,630 --> 00:19:13,250 I want to say hi class. 570 00:19:13,250 --> 00:19:15,670 But I want to keep this template. 571 00:19:15,670 --> 00:19:17,980 I don't have to rewrite the entire program again. 572 00:19:17,980 --> 00:19:19,700 I want to keep the template. 573 00:19:19,700 --> 00:19:20,480 How do I copy? 574 00:19:20,480 --> 00:19:25,580 575 00:19:25,580 --> 00:19:26,210 >> Easy. 576 00:19:26,210 --> 00:19:29,680 So cp hi.c newhi.c. 577 00:19:29,680 --> 00:19:32,767 578 00:19:32,767 --> 00:19:34,340 Now I have two. 579 00:19:34,340 --> 00:19:48,330 And then I can open up newhi.c, and instead of just saying hi, 580 00:19:48,330 --> 00:19:51,280 I'll say hi class! 581 00:19:51,280 --> 00:20:00,530 582 00:20:00,530 --> 00:20:01,780 So I'll go back. 583 00:20:01,780 --> 00:20:03,520 Exit out. 584 00:20:03,520 --> 00:20:04,990 Go back to my command line. 585 00:20:04,990 --> 00:20:06,070 ls make newhi. 586 00:20:06,070 --> 00:20:07,500 587 00:20:07,500 --> 00:20:08,140 Run it. 588 00:20:08,140 --> 00:20:09,720 589 00:20:09,720 --> 00:20:10,220 There. 590 00:20:10,220 --> 00:20:11,530 It's better, much better. 591 00:20:11,530 --> 00:20:13,600 592 00:20:13,600 --> 00:20:17,610 So if you want to copy something, easy as that. cp is copy. 593 00:20:17,610 --> 00:20:22,060 594 00:20:22,060 --> 00:20:25,355 >> So we've gone over moving, making directories, copying. 595 00:20:25,355 --> 00:20:27,434 596 00:20:27,434 --> 00:20:29,470 Let's see what else should I go over? 597 00:20:29,470 --> 00:20:30,580 598 00:20:30,580 --> 00:20:31,080 Oh, yeah. 599 00:20:31,080 --> 00:20:31,871 Let's go over this. 600 00:20:31,871 --> 00:20:32,990 601 00:20:32,990 --> 00:20:34,300 So this was awesome. 602 00:20:34,300 --> 00:20:35,710 603 00:20:35,710 --> 00:20:37,320 Let's say I wanted to-- oh wait. 604 00:20:37,320 --> 00:20:39,224 I'm going to go back into awesome. 605 00:20:39,224 --> 00:20:41,720 606 00:20:41,720 --> 00:20:46,670 >> Let's say I don't want these files right here. 607 00:20:46,670 --> 00:20:49,630 Let's say I want them in a new directory like in directory awesome. 608 00:20:49,630 --> 00:20:51,463 I want to start organizing, so now I'm going 609 00:20:51,463 --> 00:20:53,390 to have a new directory called hi. 610 00:20:53,390 --> 00:20:55,850 It's got all the programs I write called hi. 611 00:20:55,850 --> 00:20:57,000 So how do we do that? 612 00:20:57,000 --> 00:21:00,234 613 00:21:00,234 --> 00:21:01,490 >> STUDENT: Change directory. 614 00:21:01,490 --> 00:21:02,448 >> JASON HIRSCHHORN: Yeah. 615 00:21:02,448 --> 00:21:03,077 616 00:21:03,077 --> 00:21:04,070 hi. 617 00:21:04,070 --> 00:21:04,570 Boop. 618 00:21:04,570 --> 00:21:06,910 619 00:21:06,910 --> 00:21:08,370 mkdir hi_dir. 620 00:21:08,370 --> 00:21:13,578 621 00:21:13,578 --> 00:21:16,160 It complained because I already had a hi in here. 622 00:21:16,160 --> 00:21:17,260 623 00:21:17,260 --> 00:21:18,610 So now I have a hi directory. 624 00:21:18,610 --> 00:21:21,200 So now I want to move everything, all the programs I wrote, 625 00:21:21,200 --> 00:21:22,950 I want to move them into the hi directory. 626 00:21:22,950 --> 00:21:24,120 Just clean stuff up. 627 00:21:24,120 --> 00:21:25,245 How do I do that? 628 00:21:25,245 --> 00:21:26,550 >> STUDENT: [INAUDIBLE]. 629 00:21:26,550 --> 00:21:28,040 >> JASON HIRSCHHORN: Moving it, right? 630 00:21:28,040 --> 00:21:28,865 So let's move. 631 00:21:28,865 --> 00:21:34,215 632 00:21:34,215 --> 00:21:34,715 Yeah? 633 00:21:34,715 --> 00:21:38,162 >> STUDENT: What's the difference between hi and hi.c that we already have. 634 00:21:38,162 --> 00:21:39,870 JASON HIRSCHHORN: Oh, hi.c is the actual. 635 00:21:39,870 --> 00:21:41,770 So that's the file that you wrote. 636 00:21:41,770 --> 00:21:44,670 So if you were going to open it up in gedit or Nano, 637 00:21:44,670 --> 00:21:46,240 that's what you're typing in. 638 00:21:46,240 --> 00:21:48,710 When you compile it, then you get an executable file. 639 00:21:48,710 --> 00:21:49,610 That's hi. 640 00:21:49,610 --> 00:21:52,630 So if you opened up hi, that's going to be a bunch of gibberish to you. 641 00:21:52,630 --> 00:21:57,536 It's basically going to be bunch of computer instructions. 642 00:21:57,536 --> 00:21:58,036 What's up? 643 00:21:58,036 --> 00:21:59,577 >> STUDENT: What do all the colors mean? 644 00:21:59,577 --> 00:22:00,892 The blue is probably directory. 645 00:22:00,892 --> 00:22:02,010 What's yellow? 646 00:22:02,010 --> 00:22:04,051 >> JASON HIRSCHHORN: Those are the executable files. 647 00:22:04,051 --> 00:22:08,344 So when I did make hi.c, it gave me-- so I can do it. 648 00:22:08,344 --> 00:22:09,010 Jumping the gun. 649 00:22:09,010 --> 00:22:11,880 So remove hi yes. 650 00:22:11,880 --> 00:22:12,930 So then let's do ls. 651 00:22:12,930 --> 00:22:13,930 I don't have hi anymore. 652 00:22:13,930 --> 00:22:16,770 So when you make, that's when you take the program that you wrote 653 00:22:16,770 --> 00:22:18,100 and you make a executable file. 654 00:22:18,100 --> 00:22:20,720 So make hi.c-- well, make hi. 655 00:22:20,720 --> 00:22:21,956 656 00:22:21,956 --> 00:22:24,060 I think he went over this in lecture. 657 00:22:24,060 --> 00:22:25,970 >> These are bunch of compiler instructions. 658 00:22:25,970 --> 00:22:28,585 So instead of having to actually write clang with all these. 659 00:22:28,585 --> 00:22:29,860 These are flags. 660 00:22:29,860 --> 00:22:31,210 You just write make. 661 00:22:31,210 --> 00:22:32,680 So this makes the executable files. 662 00:22:32,680 --> 00:22:36,200 So when you do ls, now you have hi. 663 00:22:36,200 --> 00:22:38,320 So this is what you're going to actually run. 664 00:22:38,320 --> 00:22:45,130 And so you run that by doing ./hi, and it runs your program. 665 00:22:45,130 --> 00:22:51,066 But if I try to do that with hi.c, no, it's not going to work. 666 00:22:51,066 --> 00:22:52,190 Yeah, does that make sense? 667 00:22:52,190 --> 00:22:52,990 >> STUDENT: Mm-hm. 668 00:22:52,990 --> 00:22:53,948 >> JASON HIRSCHHORN: Cool. 669 00:22:53,948 --> 00:22:55,632 670 00:22:55,632 --> 00:22:57,330 Wait, I wanted to say something else. 671 00:22:57,330 --> 00:22:58,450 672 00:22:58,450 --> 00:23:02,226 Just real quick, in case anyone is interested, 673 00:23:02,226 --> 00:23:04,350 when you jump out of a directory, it's the dot dot. 674 00:23:04,350 --> 00:23:05,580 675 00:23:05,580 --> 00:23:08,960 Does anybody have an idea of what maybe just the singular dot means? 676 00:23:08,960 --> 00:23:15,085 677 00:23:15,085 --> 00:23:15,960 STUDENT: [INAUDIBLE]. 678 00:23:15,960 --> 00:23:16,631 679 00:23:16,631 --> 00:23:18,880 JASON HIRSCHHORN: It's actually the current directory. 680 00:23:18,880 --> 00:23:20,730 So it's your current directory. 681 00:23:20,730 --> 00:23:21,920 682 00:23:21,920 --> 00:23:22,610 So I'm here. 683 00:23:22,610 --> 00:23:23,700 I'm in awesome. 684 00:23:23,700 --> 00:23:27,090 If I do cd dot, it doesn't do anything. 685 00:23:27,090 --> 00:23:28,750 It takes me to my current directory. 686 00:23:28,750 --> 00:23:34,407 So a little redundant, but you have to do that, so ./ your program name, 687 00:23:34,407 --> 00:23:36,490 in order to run your program, you have to do that. 688 00:23:36,490 --> 00:23:38,020 689 00:23:38,020 --> 00:23:38,520 OK. 690 00:23:38,520 --> 00:23:39,555 691 00:23:39,555 --> 00:23:42,032 >> STUDENT: If you do cd dot dot dot, however many dots 692 00:23:42,032 --> 00:23:43,990 will it just take you up that many directories? 693 00:23:43,990 --> 00:23:46,527 >> JASON HIRSCHHORN: You mean like cd dot dot dot dot? 694 00:23:46,527 --> 00:23:47,110 STUDENT: Yeah. 695 00:23:47,110 --> 00:23:47,985 JASON HIRSCHHORN: No. 696 00:23:47,985 --> 00:23:48,850 697 00:23:48,850 --> 00:23:52,130 So actually Remember I did ls -l? 698 00:23:52,130 --> 00:23:53,290 699 00:23:53,290 --> 00:23:56,800 If I do something else, I can ls -a. 700 00:23:56,800 --> 00:23:59,940 So what this says is -a shows you everything. 701 00:23:59,940 --> 00:24:03,180 So it shows you things that are hidden and things that aren't hidden. 702 00:24:03,180 --> 00:24:10,880 So if you notice that when I did just ls, I just saw that stuff, 703 00:24:10,880 --> 00:24:12,060 the stuff I made. 704 00:24:12,060 --> 00:24:14,640 If I do -a, it's going to show me everything. 705 00:24:14,640 --> 00:24:18,460 And so current directory, directory above it. 706 00:24:18,460 --> 00:24:22,025 707 00:24:22,025 --> 00:24:22,900 Does that make sense? 708 00:24:22,900 --> 00:24:23,130 Yeah? 709 00:24:23,130 --> 00:24:25,296 >> STUDENT: But those aren't actually in the directory. 710 00:24:25,296 --> 00:24:30,938 The current directory isn't in itself, so why show those with dots inside? 711 00:24:30,938 --> 00:24:33,910 >> JASON HIRSCHHORN: You mean it's like it's not in the directory. 712 00:24:33,910 --> 00:24:34,810 >> STUDENT: Right. 713 00:24:34,810 --> 00:24:36,620 So we have a list of things that are in the directory. 714 00:24:36,620 --> 00:24:37,630 >> JASON HIRSCHHORN: I think it is in the directory. 715 00:24:37,630 --> 00:24:41,190 Like -a shows everything, even if it's hidden inside the directory. 716 00:24:41,190 --> 00:24:44,440 So I think it's just a route to the current directory if that makes sense. 717 00:24:44,440 --> 00:24:46,400 718 00:24:46,400 --> 00:24:47,400 It's a little recursive. 719 00:24:47,400 --> 00:24:48,300 It's like Inception. 720 00:24:48,300 --> 00:24:48,920 What's up? 721 00:24:48,920 --> 00:24:52,090 >> STUDENT: So you said -a shows [INAUDIBLE]? 722 00:24:52,090 --> 00:24:53,215 JASON HIRSCHHORN: -a, yeah. 723 00:24:53,215 --> 00:24:54,964 724 00:24:54,964 --> 00:24:56,572 >> STUDENT: What makes it [INAUDIBLE]? 725 00:24:56,572 --> 00:24:59,280 JASON HIRSCHHORN: Well, for example, let's go back up to the top. 726 00:24:59,280 --> 00:25:00,890 727 00:25:00,890 --> 00:25:04,180 It's usually stuff you shouldn't mess with and you don't need to worry about. 728 00:25:04,180 --> 00:25:07,180 So this is kind of the home. 729 00:25:07,180 --> 00:25:10,230 If I do -a, I get tons of stuff. 730 00:25:10,230 --> 00:25:14,760 731 00:25:14,760 --> 00:25:15,440 All that stuff. 732 00:25:15,440 --> 00:25:18,840 733 00:25:18,840 --> 00:25:21,258 And you don't need to mess with any of that stuff. 734 00:25:21,258 --> 00:25:23,716 Definitely don't start going in here and just remove stuff. 735 00:25:23,716 --> 00:25:27,190 >> [LAUGHTER] 736 00:25:27,190 --> 00:25:32,440 >> Yeah, this was a little bit more comfy stuff, but it's good to know. 737 00:25:32,440 --> 00:25:34,310 I think it's good to know. 738 00:25:34,310 --> 00:25:35,540 739 00:25:35,540 --> 00:25:41,420 But if you never want to type -a in the entirety of this course, 740 00:25:41,420 --> 00:25:42,540 just forget it. 741 00:25:42,540 --> 00:25:43,040 What's up? 742 00:25:43,040 --> 00:25:44,436 >> STUDENT: What is the ls -l? 743 00:25:44,436 --> 00:25:46,310 JASON HIRSCHHORN: That shows you permissions. 744 00:25:46,310 --> 00:25:50,269 Basically you use that for permissions, so -l. 745 00:25:50,269 --> 00:25:52,060 It shows you a little bit more information, 746 00:25:52,060 --> 00:25:54,840 but again, this is a little bit more comfy stuff. 747 00:25:54,840 --> 00:25:56,040 These are just permissions. 748 00:25:56,040 --> 00:25:57,710 So the permissions of the folders. 749 00:25:57,710 --> 00:26:04,459 So just for example, let's say I made a folder, so the d represents directory. 750 00:26:04,459 --> 00:26:05,500 So those are directories. 751 00:26:05,500 --> 00:26:08,250 And then read, write, execute. 752 00:26:08,250 --> 00:26:12,610 So those are permissions for I think user, group, world. 753 00:26:12,610 --> 00:26:14,490 754 00:26:14,490 --> 00:26:15,610 Totally going too far. 755 00:26:15,610 --> 00:26:18,580 You're going to go in this like weeks from now, but just so you know, 756 00:26:18,580 --> 00:26:19,340 those are permissions. 757 00:26:19,340 --> 00:26:19,840 What's up? 758 00:26:19,840 --> 00:26:23,189 STUDENT: Can you clear rather than just skip to the next thing, can you-- 759 00:26:23,189 --> 00:26:24,980 JASON HIRSCHHORN: You mean actually delete? 760 00:26:24,980 --> 00:26:25,859 761 00:26:25,859 --> 00:26:26,400 I don't know. 762 00:26:26,400 --> 00:26:27,450 I never do that. 763 00:26:27,450 --> 00:26:28,700 Why would you want to do that? 764 00:26:28,700 --> 00:26:29,782 765 00:26:29,782 --> 00:26:30,698 Why would you do that? 766 00:26:30,698 --> 00:26:32,330 767 00:26:32,330 --> 00:26:32,840 I like it. 768 00:26:32,840 --> 00:26:34,020 You live on the edge. 769 00:26:34,020 --> 00:26:35,561 You're like I don't want any of this. 770 00:26:35,561 --> 00:26:40,380 771 00:26:40,380 --> 00:26:41,096 That's intense. 772 00:26:41,096 --> 00:26:41,970 STUDENT: [INAUDIBLE]. 773 00:26:41,970 --> 00:26:43,541 774 00:26:43,541 --> 00:26:45,165 JASON HIRSCHHORN: Yeah, we can do that. 775 00:26:45,165 --> 00:26:47,960 776 00:26:47,960 --> 00:26:52,667 Sorry, messing with the size is totally freaking me out right now. 777 00:26:52,667 --> 00:26:53,920 778 00:26:53,920 --> 00:26:54,950 Let's go up. 779 00:26:54,950 --> 00:26:56,759 Yeah, so now I can't go up anymore. 780 00:26:56,759 --> 00:26:58,550 So everything I taught you is gone forever. 781 00:26:58,550 --> 00:26:59,050 Thank you. 782 00:26:59,050 --> 00:27:04,311 783 00:27:04,311 --> 00:27:05,310 We made our directories. 784 00:27:05,310 --> 00:27:08,268 We made our files and stuff like that, so we still have all that stuff. 785 00:27:08,268 --> 00:27:10,270 786 00:27:10,270 --> 00:27:11,200 OK, I'll go fast. 787 00:27:11,200 --> 00:27:13,300 788 00:27:13,300 --> 00:27:14,100 >> So real quick. 789 00:27:14,100 --> 00:27:15,520 So let's say I'm in awesome. 790 00:27:15,520 --> 00:27:17,480 791 00:27:17,480 --> 00:27:20,090 Let's say I wanted to move everything to the new directory 792 00:27:20,090 --> 00:27:21,600 because I just want to organize it, right? 793 00:27:21,600 --> 00:27:22,560 So how would I do that. 794 00:27:22,560 --> 00:27:23,650 795 00:27:23,650 --> 00:27:24,150 Move. 796 00:27:24,150 --> 00:27:25,399 We're going to use move again. 797 00:27:25,399 --> 00:27:26,320 So move hi.c. 798 00:27:26,320 --> 00:27:27,620 799 00:27:27,620 --> 00:27:29,810 And what you can do is you start listing stuff, 800 00:27:29,810 --> 00:27:32,268 and the last thing you list is where it's going to move it. 801 00:27:32,268 --> 00:27:38,230 So move hi.c, hi newhi newhi.c, hi_dir. 802 00:27:38,230 --> 00:27:41,960 803 00:27:41,960 --> 00:27:45,880 And so it moved everything into the last thing you mentioned. 804 00:27:45,880 --> 00:27:49,462 So then change directory, hi_dir ls. 805 00:27:49,462 --> 00:27:50,420 Everything is in there. 806 00:27:50,420 --> 00:27:52,625 So it's nice and more organized. 807 00:27:52,625 --> 00:27:53,970 808 00:27:53,970 --> 00:27:57,330 >> OK, let's say I hate my original hi program. 809 00:27:57,330 --> 00:27:58,700 I want to get rid of it. 810 00:27:58,700 --> 00:28:00,380 How do I get rid of it? 811 00:28:00,380 --> 00:28:00,880 What's up? 812 00:28:00,880 --> 00:28:01,755 >> STUDENT: [INAUDIBLE]. 813 00:28:01,755 --> 00:28:04,977 814 00:28:04,977 --> 00:28:08,060 JASON HIRSCHHORN: Let's say I just want to remove the program, so just hi. 815 00:28:08,060 --> 00:28:11,122 816 00:28:11,122 --> 00:28:11,830 No, you're right. 817 00:28:11,830 --> 00:28:14,680 So it's rm, but you do rm hi. 818 00:28:14,680 --> 00:28:18,224 819 00:28:18,224 --> 00:28:19,890 It's going to give you a little warning. 820 00:28:19,890 --> 00:28:25,440 It's going to say are you sure you want to delete this, and yes I do. 821 00:28:25,440 --> 00:28:27,190 If you don't want to be prompted like that 822 00:28:27,190 --> 00:28:34,260 because you don't have time for warnings, remove -f. 823 00:28:34,260 --> 00:28:35,720 This is another flag. 824 00:28:35,720 --> 00:28:36,910 It's like the -l. 825 00:28:36,910 --> 00:28:38,190 It's like the -a. 826 00:28:38,190 --> 00:28:40,610 These are just flags that you're giving to these commands. 827 00:28:40,610 --> 00:28:41,490 So remove -f. 828 00:28:41,490 --> 00:28:42,540 829 00:28:42,540 --> 00:28:44,340 -f f means force. 830 00:28:44,340 --> 00:28:45,670 So force it. 831 00:28:45,670 --> 00:28:47,390 I do not want to be prompted. 832 00:28:47,390 --> 00:28:48,560 So remove -f. 833 00:28:48,560 --> 00:28:49,920 834 00:28:49,920 --> 00:28:50,720 Let's do hi.c. 835 00:28:50,720 --> 00:28:53,589 836 00:28:53,589 --> 00:28:54,380 Just got rid of it. 837 00:28:54,380 --> 00:28:55,130 It didn't tell me. 838 00:28:55,130 --> 00:28:56,160 839 00:28:56,160 --> 00:28:59,270 >> But let's say instead I'm done with this directory. 840 00:28:59,270 --> 00:29:01,010 I want to get rid of directory. 841 00:29:01,010 --> 00:29:02,950 So I do remove hi_dir. 842 00:29:02,950 --> 00:29:04,124 843 00:29:04,124 --> 00:29:05,040 No, that doesn't work. 844 00:29:05,040 --> 00:29:11,170 845 00:29:11,170 --> 00:29:13,685 No, so it won't let me remove a directory. 846 00:29:13,685 --> 00:29:15,770 847 00:29:15,770 --> 00:29:17,010 Does anybody have an idea? 848 00:29:17,010 --> 00:29:18,752 >> STUDENT: Is it remove dir? 849 00:29:18,752 --> 00:29:20,335 JASON HIRSCHHORN: So remove like this? 850 00:29:20,335 --> 00:29:24,961 851 00:29:24,961 --> 00:29:26,398 >> STUDENT: No. 852 00:29:26,398 --> 00:29:27,835 Just the [INAUDIBLE]. 853 00:29:27,835 --> 00:29:29,024 854 00:29:29,024 --> 00:29:30,940 JASON HIRSCHHORN: No, right now there's no hi. 855 00:29:30,940 --> 00:29:32,099 There's just hi_dir. 856 00:29:32,099 --> 00:29:33,140 So this is the directory. 857 00:29:33,140 --> 00:29:34,730 858 00:29:34,730 --> 00:29:37,930 So actually what you want to do is-- oh, do you have an idea? 859 00:29:37,930 --> 00:29:39,281 I see like a half hand. 860 00:29:39,281 --> 00:29:40,156 >> STUDENT: [INAUDIBLE]. 861 00:29:40,156 --> 00:29:41,215 862 00:29:41,215 --> 00:29:42,090 JASON HIRSCHHORN: OK. 863 00:29:42,090 --> 00:29:43,232 864 00:29:43,232 --> 00:29:44,470 >> STUDENT: [INAUDIBLE]. 865 00:29:44,470 --> 00:29:45,345 >> JASON HIRSCHHORN: OK. 866 00:29:45,345 --> 00:29:48,200 867 00:29:48,200 --> 00:29:51,790 So if I want to remove a directory, remove -r. 868 00:29:51,790 --> 00:29:52,580 That's recursive. 869 00:29:52,580 --> 00:29:54,230 So remove that directory recursive. 870 00:29:54,230 --> 00:29:57,700 So I want you to go into that directory, remove everything in the directory, 871 00:29:57,700 --> 00:29:59,180 and then get rid of the directory. 872 00:29:59,180 --> 00:30:00,930 And then I'm going to f as well, because I 873 00:30:00,930 --> 00:30:04,680 don't want it to prompt me with warnings after it removes every single file. 874 00:30:04,680 --> 00:30:06,720 So remove -rf hi_dir. 875 00:30:06,720 --> 00:30:08,680 876 00:30:08,680 --> 00:30:09,540 Boom, it's gone. 877 00:30:09,540 --> 00:30:10,582 878 00:30:10,582 --> 00:30:12,040 Just be careful where you use that. 879 00:30:12,040 --> 00:30:14,730 I'm going to use it here too. -rf awesome. 880 00:30:14,730 --> 00:30:16,800 881 00:30:16,800 --> 00:30:17,530 It's gone. 882 00:30:17,530 --> 00:30:18,780 Be careful where you use that. 883 00:30:18,780 --> 00:30:22,990 If you use that here and type something like this, don't ever do that. 884 00:30:22,990 --> 00:30:26,200 That will delete everything on your appliance without ever warning you. 885 00:30:26,200 --> 00:30:27,670 And I've done that. 886 00:30:27,670 --> 00:30:31,620 Grading problem sets at 4:00 AM, I was trying remove problem set directories, 887 00:30:31,620 --> 00:30:32,320 and I did this. 888 00:30:32,320 --> 00:30:34,080 And I was like oh my god. 889 00:30:34,080 --> 00:30:35,170 890 00:30:35,170 --> 00:30:36,850 Don't do-- I tried to cancel it. 891 00:30:36,850 --> 00:30:38,000 You can cancel. 892 00:30:38,000 --> 00:30:42,670 Command C just cancels everything, but I already deleted like 75%. 893 00:30:42,670 --> 00:30:45,570 So I ruined it. 894 00:30:45,570 --> 00:30:46,580 And people do that. 895 00:30:46,580 --> 00:30:47,620 Everyone does this. 896 00:30:47,620 --> 00:30:49,460 Don't do this though this semester. 897 00:30:49,460 --> 00:30:49,960 It sucks. 898 00:30:49,960 --> 00:30:52,330 899 00:30:52,330 --> 00:30:54,050 I'm nervous having it here. 900 00:30:54,050 --> 00:30:55,247 I'm going to delete it. 901 00:30:55,247 --> 00:30:58,354 >> [LAUGHTER] 902 00:30:58,354 --> 00:30:59,020 Can you imagine? 903 00:30:59,020 --> 00:31:01,050 904 00:31:01,050 --> 00:31:02,450 OK, questions. 905 00:31:02,450 --> 00:31:03,138 Yes? 906 00:31:03,138 --> 00:31:09,114 >> STUDENT: So if we do everything you're doing here, is this the same 907 00:31:09,114 --> 00:31:13,791 as just going into actually file save as [INAUDIBLE]. 908 00:31:13,791 --> 00:31:16,530 909 00:31:16,530 --> 00:31:18,405 JASON HIRSCHHORN: Oh, you mean through gedit. 910 00:31:18,405 --> 00:31:18,870 STUDENT: Yeah. 911 00:31:18,870 --> 00:31:20,078 JASON HIRSCHHORN: Yeah it is. 912 00:31:20,078 --> 00:31:21,094 913 00:31:21,094 --> 00:31:21,760 gedit is useful. 914 00:31:21,760 --> 00:31:23,440 915 00:31:23,440 --> 00:31:24,730 So gedit is very useful. 916 00:31:24,730 --> 00:31:26,550 In this class, you can do a lot of things through gedit. 917 00:31:26,550 --> 00:31:27,260 You can save. 918 00:31:27,260 --> 00:31:27,980 You can rename. 919 00:31:27,980 --> 00:31:34,170 You can move files and stuff like that, but just truthfully when you go to 50-- 920 00:31:34,170 --> 00:31:40,330 well you are in 50-- 51, if you go into 61, this is going to be your life. 921 00:31:40,330 --> 00:31:41,590 This is the command line. 922 00:31:41,590 --> 00:31:44,220 This is where you will program for the rest of your life, 923 00:31:44,220 --> 00:31:47,050 so definitely use gedit if you want. 924 00:31:47,050 --> 00:31:47,929 925 00:31:47,929 --> 00:31:49,220 Definitely a good way to start. 926 00:31:49,220 --> 00:31:52,550 For the first problem sets, definitely use, but every once in a while 927 00:31:52,550 --> 00:31:56,790 try to get more used more comfortable with command line arguments. 928 00:31:56,790 --> 00:31:58,230 But you can, definitely. 929 00:31:58,230 --> 00:31:58,730 What's up? 930 00:31:58,730 --> 00:32:01,660 >> STUDENT: So when we want to delete one of the files we've made, 931 00:32:01,660 --> 00:32:04,426 there are two ways. [INAUDIBLE]. 932 00:32:04,426 --> 00:32:06,385 Is there a way when you're deleting a directory 933 00:32:06,385 --> 00:32:08,467 to ask for prompt so you don't end up deleting it? 934 00:32:08,467 --> 00:32:09,610 JASON HIRSCHHORN: rm -r. 935 00:32:09,610 --> 00:32:10,810 So don't force it. 936 00:32:10,810 --> 00:32:11,489 So rm -r. 937 00:32:11,489 --> 00:32:14,280 It's going to go through recursively, delete everything, prompt you 938 00:32:14,280 --> 00:32:17,340 after everything, which will drive you nuts. 939 00:32:17,340 --> 00:32:18,660 940 00:32:18,660 --> 00:32:24,060 Like I almost exclusively do rm -f and rm -rf, just constantly. 941 00:32:24,060 --> 00:32:26,298 I'm like I don't have time. 942 00:32:26,298 --> 00:32:27,600 I'm a busy man. 943 00:32:27,600 --> 00:32:28,580 All right, what's up? 944 00:32:28,580 --> 00:32:29,170 Yeah. 945 00:32:29,170 --> 00:32:32,015 >> STUDENT: Is there an undo, or a trash bin, or anything like that? 946 00:32:32,015 --> 00:32:32,890 JASON HIRSCHHORN: No. 947 00:32:32,890 --> 00:32:35,120 [LAUGHTER] 948 00:32:35,120 --> 00:32:39,100 I could go back and get my appliance that I just deleted, no. 949 00:32:39,100 --> 00:32:39,600 No, no, no. 950 00:32:39,600 --> 00:32:41,390 951 00:32:41,390 --> 00:32:43,030 If you do rm, it should be gone. 952 00:32:43,030 --> 00:32:43,963 What's up? 953 00:32:43,963 --> 00:32:46,785 >> STUDENT: So you can [INAUDIBLE] together. 954 00:32:46,785 --> 00:32:48,410 JASON HIRSCHHORN: Yeah, just like that. 955 00:32:48,410 --> 00:32:52,190 So for example, you saw the rm -rf. 956 00:32:52,190 --> 00:32:55,700 Let's say I want to do ls -la, it shows me 957 00:32:55,700 --> 00:33:00,120 everything, even hidden things with their permissions. 958 00:33:00,120 --> 00:33:02,160 959 00:33:02,160 --> 00:33:06,762 >> STUDENT: So then r, the -r flag, if we don't have that, 960 00:33:06,762 --> 00:33:08,250 we can't delete a directory, right? 961 00:33:08,250 --> 00:33:08,746 >> JASON HIRSCHHORN: Right. 962 00:33:08,746 --> 00:33:10,990 >> STUDENT: So that says that we want to do something with the directory? 963 00:33:10,990 --> 00:33:12,610 Is that what that means? 964 00:33:12,610 --> 00:33:14,570 >> JASON HIRSCHHORN: -r means recursively. 965 00:33:14,570 --> 00:33:17,670 So a directory is going to have files in it, right? 966 00:33:17,670 --> 00:33:21,680 So what you want to do is you want to go into that directory, 967 00:33:21,680 --> 00:33:24,110 delete everything, all the files in that directory, 968 00:33:24,110 --> 00:33:26,510 then pop out and delete the actual directory. 969 00:33:26,510 --> 00:33:30,660 So the -r means recursive, do it all recursively if that makes sense. 970 00:33:30,660 --> 00:33:31,160 Yeah. 971 00:33:31,160 --> 00:33:34,160 >> STUDENT: So directories have [INAUDIBLE] and just delete it. 972 00:33:34,160 --> 00:33:35,160 Or do you still-- 973 00:33:35,160 --> 00:33:36,326 >> JASON HIRSCHHORN: Let's try. 974 00:33:36,326 --> 00:33:39,040 975 00:33:39,040 --> 00:33:40,955 So mkdir empty. 976 00:33:40,955 --> 00:33:42,320 977 00:33:42,320 --> 00:33:43,810 Remove empty. 978 00:33:43,810 --> 00:33:44,374 No. 979 00:33:44,374 --> 00:33:45,646 >> STUDENT: No, so you still need the-- 980 00:33:45,646 --> 00:33:46,937 >> JASON HIRSCHHORN: Yeah, always. 981 00:33:46,937 --> 00:33:48,940 So -r, -rf, empty. 982 00:33:48,940 --> 00:33:50,432 983 00:33:50,432 --> 00:33:51,734 Awesome. 984 00:33:51,734 --> 00:33:52,685 Anymore questions? 985 00:33:52,685 --> 00:33:54,290 986 00:33:54,290 --> 00:33:59,230 I think that is your crash course on command line stuff. 987 00:33:59,230 --> 00:34:02,560 Any questions, because we're going to jump over to data types, and loops, 988 00:34:02,560 --> 00:34:03,901 and all that stuff? 989 00:34:03,901 --> 00:34:04,400 What's up? 990 00:34:04,400 --> 00:34:07,960 >> STUDENT: I don't have CS50 showing as one of my directories. 991 00:34:07,960 --> 00:34:09,370 Is that normal? 992 00:34:09,370 --> 00:34:09,710 >> JASON HIRSCHHORN: Oh, yeah. 993 00:34:09,710 --> 00:34:10,929 That's mine. 994 00:34:10,929 --> 00:34:14,830 Yeah, that's where my solutions to your stuff is. 995 00:34:14,830 --> 00:34:17,670 >> [LAUGHTER] 996 00:34:17,670 --> 00:34:20,469 >> So yeah, that's absolutely normal. 997 00:34:20,469 --> 00:34:23,870 I think you'll probably just have these four. 998 00:34:23,870 --> 00:34:25,130 I think that might be normal. 999 00:34:25,130 --> 00:34:25,630 Yeah. 1000 00:34:25,630 --> 00:34:27,370 1001 00:34:27,370 --> 00:34:28,730 OK, any more questions? 1002 00:34:28,730 --> 00:34:30,219 I know that was super fast. 1003 00:34:30,219 --> 00:34:30,830 What's up? 1004 00:34:30,830 --> 00:34:33,788 >> STUDENT: I saw the blue green color. 1005 00:34:33,788 --> 00:34:34,780 What is that? 1006 00:34:34,780 --> 00:34:36,405 >> JASON HIRSCHHORN: That means directory. 1007 00:34:36,405 --> 00:34:36,905 1008 00:34:36,905 --> 00:34:38,000 STUDENT: And this blue? 1009 00:34:38,000 --> 00:34:40,100 >> JASON HIRSCHHORN: Oh, you mean this blue green? 1010 00:34:40,100 --> 00:34:41,290 >> STUDENT: No. 1011 00:34:41,290 --> 00:34:41,724 >> JASON HIRSCHHORN: This blue green? 1012 00:34:41,724 --> 00:34:42,434 >> STUDENT: No. 1013 00:34:42,434 --> 00:34:43,195 When you listed-- 1014 00:34:43,195 --> 00:34:44,070 JASON HIRSCHHORN: Oh. 1015 00:34:44,070 --> 00:34:47,100 1016 00:34:47,100 --> 00:34:47,620 Like this? 1017 00:34:47,620 --> 00:34:49,000 >> STUDENT: Yes, the icons. 1018 00:34:49,000 --> 00:34:50,125 >> JASON HIRSCHHORN: Oh, this. 1019 00:34:50,125 --> 00:34:50,678 1020 00:34:50,678 --> 00:34:51,219 I don't know. 1021 00:34:51,219 --> 00:34:52,052 What does that mean? 1022 00:34:52,052 --> 00:34:58,330 1023 00:34:58,330 --> 00:35:00,100 So it seems to be pointing to a directory. 1024 00:35:00,100 --> 00:35:02,240 >> STUDENT: It almost looks like an alias. 1025 00:35:02,240 --> 00:35:03,594 >> JASON HIRSCHHORN: It might be. 1026 00:35:03,594 --> 00:35:04,760 You don't need to know that. 1027 00:35:04,760 --> 00:35:11,205 1028 00:35:11,205 --> 00:35:11,955 Anymore questions? 1029 00:35:11,955 --> 00:35:14,180 1030 00:35:14,180 --> 00:35:14,680 Awesome. 1031 00:35:14,680 --> 00:35:16,900 If you have any questions, I know that was a lot. 1032 00:35:16,900 --> 00:35:18,190 A lot of this information will be online. 1033 00:35:18,190 --> 00:35:19,750 I'll put it online for you guys. 1034 00:35:19,750 --> 00:35:21,187 Section B will be online as well. 1035 00:35:21,187 --> 00:35:23,270 Or if you have questions, just come up and ask me. 1036 00:35:23,270 --> 00:35:30,660 1037 00:35:30,660 --> 00:35:32,142 Here you go. 1038 00:35:32,142 --> 00:35:41,050 1039 00:35:41,050 --> 00:35:44,400 So now Sharon and Hannah will go over some 1040 00:35:44,400 --> 00:35:46,720 of the logic behind problem set one. 1041 00:35:46,720 --> 00:35:53,266 1042 00:35:53,266 --> 00:35:54,250 >> SHARON: Oh my god. 1043 00:35:54,250 --> 00:35:56,218 1044 00:35:56,218 --> 00:35:57,694 Troubles. 1045 00:35:57,694 --> 00:35:59,170 >> HANNAH: In the meantime, I'm Hanna. 1046 00:35:59,170 --> 00:36:00,154 This is Sharon. 1047 00:36:00,154 --> 00:36:03,106 We are both CS50 TFs, and we're going to give you 1048 00:36:03,106 --> 00:36:06,050 a little intro on a couple important things for problem set one. 1049 00:36:06,050 --> 00:36:09,670 Everything from data types to conditionals to for loops. 1050 00:36:09,670 --> 00:36:10,620 Loops in general. 1051 00:36:10,620 --> 00:36:14,360 >> SHARON: And in the end, we will take a look at P set one, 1052 00:36:14,360 --> 00:36:16,739 and what you have to know for it. 1053 00:36:16,739 --> 00:36:18,030 So let's start with data types. 1054 00:36:18,030 --> 00:36:19,840 1055 00:36:19,840 --> 00:36:23,230 You guys should be familiar with the ones that are highlighted in blue. 1056 00:36:23,230 --> 00:36:25,340 So we can start with ints. 1057 00:36:25,340 --> 00:36:31,500 ints are integers, so one, two, three, four. floats, floating points. 1058 00:36:31,500 --> 00:36:37,830 Like integers with decimals, so 5.2 or even 5.0. 1059 00:36:37,830 --> 00:36:44,230 Chars are characters like A, B, C. And a string, you guys all know. 1060 00:36:44,230 --> 00:36:48,470 Like CS50 or hello and world. 1061 00:36:48,470 --> 00:36:50,290 1062 00:36:50,290 --> 00:36:56,890 >> Bool is a Boolean, so we have true and false as our Boolean. 1063 00:36:56,890 --> 00:37:01,550 So if something computes to truth-- 5 equals 5, that computes to true, 1064 00:37:01,550 --> 00:37:06,470 and if we have 5 equals 4, that's false, so that computes to false. 1065 00:37:06,470 --> 00:37:12,280 And here we have the associated size of all of these data types. 1066 00:37:12,280 --> 00:37:14,860 And you will have to know this for your quizzes, 1067 00:37:14,860 --> 00:37:18,412 so this might be helpful to remember, but we'll post these. 1068 00:37:18,412 --> 00:37:19,745 Actually they're already posted. 1069 00:37:19,745 --> 00:37:21,921 1070 00:37:21,921 --> 00:37:24,420 So you should be familiar with the ones highlighted in blue. 1071 00:37:24,420 --> 00:37:27,900 1072 00:37:27,900 --> 00:37:30,580 >> JASON HIRSCHHORN: Real quick, just in case you 1073 00:37:30,580 --> 00:37:34,096 want to know the difference between a char and a string. 1074 00:37:34,096 --> 00:37:45,020 So when you're writing stuff, whenever you have something like "hi," 1075 00:37:45,020 --> 00:37:46,340 that's going to be a string. 1076 00:37:46,340 --> 00:37:48,090 So if there are two quotes, it's a string. 1077 00:37:48,090 --> 00:37:52,890 But if I were to an "h" like that, that's a string. 1078 00:37:52,890 --> 00:37:55,759 But if I only have one quote, that's a char. 1079 00:37:55,759 --> 00:37:57,550 And so what's the difference you might ask. 1080 00:37:57,550 --> 00:38:00,985 Well, the difference is this is one byte of memory. 1081 00:38:00,985 --> 00:38:02,265 This is 4 bytes of memory. 1082 00:38:02,265 --> 00:38:09,480 1083 00:38:09,480 --> 00:38:10,520 >> SHARON: float? 1084 00:38:10,520 --> 00:38:12,180 Describe it again? 1085 00:38:12,180 --> 00:38:18,200 OK, it's kind of like a number that has a decimal point with it, 1086 00:38:18,200 --> 00:38:27,569 so 5.2 or even 5.0 is a float versus just 5 is an int. 1087 00:38:27,569 --> 00:38:28,444 STUDENT: [INAUDIBLE]. 1088 00:38:28,444 --> 00:38:30,240 1089 00:38:30,240 --> 00:38:36,301 >> SHARON: Oh, it can have many decimal points, so 5.675 to 3.1415. 1090 00:38:36,301 --> 00:38:36,800 Yes? 1091 00:38:36,800 --> 00:38:39,716 >> STUDENT: Do we need to know all the sizes for this? 1092 00:38:39,716 --> 00:38:40,216 SHARON: Yes. 1093 00:38:40,216 --> 00:38:41,293 1094 00:38:41,293 --> 00:38:42,168 STUDENT: [INAUDIBLE]. 1095 00:38:42,168 --> 00:38:45,810 1096 00:38:45,810 --> 00:38:49,250 >> SHARON: You don't worry about the white ones just yet. 1097 00:38:49,250 --> 00:38:54,349 >> HANNAH: The notes are posted at CS50.net/sections. 1098 00:38:54,349 --> 00:38:56,432 STUDENT: Just out of curiosity, is there a utility 1099 00:38:56,432 --> 00:39:00,424 to knowing the size of the files you're calling so that we should know it? 1100 00:39:00,424 --> 00:39:01,430 1101 00:39:01,430 --> 00:39:04,330 >> SHARON: So these are the data types, but yes. 1102 00:39:04,330 --> 00:39:09,820 So in this case, which one would take up more memory or more space? 1103 00:39:09,820 --> 00:39:13,940 >> JASON HIRSCHHORN: So for a concrete example, 1104 00:39:13,940 --> 00:39:16,904 in I think problem set four or five, we're 1105 00:39:16,904 --> 00:39:19,070 going to give you a bunch of data, and you basically 1106 00:39:19,070 --> 00:39:20,710 have to traverse that data. 1107 00:39:20,710 --> 00:39:24,470 So it's useful to know that if you have so many integers, 1108 00:39:24,470 --> 00:39:25,770 that's going to be what. 1109 00:39:25,770 --> 00:39:28,802 So let's say I gave you ten integers, what's the size of that? 1110 00:39:28,802 --> 00:39:30,111 1111 00:39:30,111 --> 00:39:30,610 STUDENT: 40. 1112 00:39:30,610 --> 00:39:32,026 JASON HIRSCHHORN: 40 bytes, right. 1113 00:39:32,026 --> 00:39:35,690 So you might need to know that OK, I need to jump 40 bytes. 1114 00:39:35,690 --> 00:39:42,200 So let's say instead it's 40 chars, then-- let's say I gave you 10 chars, 1115 00:39:42,200 --> 00:39:44,860 then you know, OK, I only need to jump 10 bytes. 1116 00:39:44,860 --> 00:39:47,651 So it's very useful to know the size of the actual data types, 1117 00:39:47,651 --> 00:39:49,900 because a lot times you'll be jumping around the data, 1118 00:39:49,900 --> 00:39:51,399 so you need to know how far to jump. 1119 00:39:51,399 --> 00:39:53,854 1120 00:39:53,854 --> 00:39:56,780 >> STUDENT: What's the difference between the quotes and one quote? 1121 00:39:56,780 --> 00:39:58,670 >> JASON HIRSCHHORN: OK, two quotes is a string. 1122 00:39:58,670 --> 00:40:00,423 One quote is a char. 1123 00:40:00,423 --> 00:40:03,570 >> STUDENT: Like operationally, what's the difference? 1124 00:40:03,570 --> 00:40:04,466 They both say hi. 1125 00:40:04,466 --> 00:40:05,094 1126 00:40:05,094 --> 00:40:06,260 JASON HIRSCHHORN: Oh, sorry. 1127 00:40:06,260 --> 00:40:07,870 This is just h. 1128 00:40:07,870 --> 00:40:09,585 Sorry, this is not clear. 1129 00:40:09,585 --> 00:40:10,920 1130 00:40:10,920 --> 00:40:12,412 >> STUDENT: So the top one-- 1131 00:40:12,412 --> 00:40:14,120 JASON HIRSCHHORN: This is a string, yeah. 1132 00:40:14,120 --> 00:40:15,430 So it's two characters, right? 1133 00:40:15,430 --> 00:40:16,360 String, hi. 1134 00:40:16,360 --> 00:40:19,030 But let's say I just had a single character, 1135 00:40:19,030 --> 00:40:23,220 if I put two quotes around just h, that's a string. 1136 00:40:23,220 --> 00:40:24,500 This is a string h. 1137 00:40:24,500 --> 00:40:25,660 1138 00:40:25,660 --> 00:40:26,940 Does that make sense? 1139 00:40:26,940 --> 00:40:28,705 So this is four bytes. 1140 00:40:28,705 --> 00:40:31,660 But let's say I got rid of that an only put one. 1141 00:40:31,660 --> 00:40:33,940 1142 00:40:33,940 --> 00:40:34,830 One quote. 1143 00:40:34,830 --> 00:40:37,140 This is now a char, a char h. 1144 00:40:37,140 --> 00:40:38,440 1145 00:40:38,440 --> 00:40:42,410 So exact same thing, different data type. 1146 00:40:42,410 --> 00:40:45,330 This is only one byte, whereas the string was four bytes. 1147 00:40:45,330 --> 00:40:45,830 Yeah. 1148 00:40:45,830 --> 00:40:48,214 1149 00:40:48,214 --> 00:40:50,630 STUDENT: So if you were trying to store a word like David, 1150 00:40:50,630 --> 00:40:54,436 you would want to use a string because regardless of how long the string is, 1151 00:40:54,436 --> 00:40:57,760 it will only take four bytes unless it's a long long 1152 00:40:57,760 --> 00:41:02,530 or a double, in which case-- so if it extends beyond four characters, then 1153 00:41:02,530 --> 00:41:04,435 you want to make it into string. 1154 00:41:04,435 --> 00:41:05,810 Is that the general logic behind. 1155 00:41:05,810 --> 00:41:06,537 1156 00:41:06,537 --> 00:41:09,370 JASON HIRSCHHORN: If it extends beyond one character, it's a string. 1157 00:41:09,370 --> 00:41:10,640 1158 00:41:10,640 --> 00:41:14,880 >> STUDENT: So there's no [INAUDIBLE] to storing a four letter 1159 00:41:14,880 --> 00:41:18,370 word as four individual or three letter word as three individual characters 1160 00:41:18,370 --> 00:41:22,050 because that will only be three bytes, as opposed to the three part string. 1161 00:41:22,050 --> 00:41:23,611 1162 00:41:23,611 --> 00:41:25,110 JASON HIRSCHHORN: You could do that. 1163 00:41:25,110 --> 00:41:27,850 1164 00:41:27,850 --> 00:41:31,070 You could do that, but I don't think that's really worthwhile, 1165 00:41:31,070 --> 00:41:32,570 because you're only saving one byte. 1166 00:41:32,570 --> 00:41:33,310 You know what I'm saying? 1167 00:41:33,310 --> 00:41:35,559 In the big scheme of things, that won't really matter. 1168 00:41:35,559 --> 00:41:39,210 But for example, printf, if you're printing f and you 1169 00:41:39,210 --> 00:41:43,430 have three chars you can print that out-- let's say you C-A-T, 1170 00:41:43,430 --> 00:41:47,680 you can print out cat just by doing one char one char one char, 1171 00:41:47,680 --> 00:41:49,980 or can you print out string cat. 1172 00:41:49,980 --> 00:41:51,140 It's the exact same thing. 1173 00:41:51,140 --> 00:41:52,870 So you could do it like that, but-- 1174 00:41:52,870 --> 00:41:54,330 >> STUDENT: It's not going to save you that much. 1175 00:41:54,330 --> 00:41:54,720 >> JASON HIRSCHHORN: Yeah. 1176 00:41:54,720 --> 00:41:57,125 The headache that it would induce is not worth it. 1177 00:41:57,125 --> 00:41:59,049 1178 00:41:59,049 --> 00:42:00,020 Yeah? 1179 00:42:00,020 --> 00:42:02,920 >> STUDENT: For example, you had the h with one 1180 00:42:02,920 --> 00:42:05,410 versus two, the single or double quotes. 1181 00:42:05,410 --> 00:42:08,760 Why would you want to save a single letter as a string. 1182 00:42:08,760 --> 00:42:11,569 What purpose does that ever serve? 1183 00:42:11,569 --> 00:42:12,860 JASON HIRSCHHORN: I don't know. 1184 00:42:12,860 --> 00:42:14,568 I mean, it really depends on the program. 1185 00:42:14,568 --> 00:42:16,060 1186 00:42:16,060 --> 00:42:20,800 For example, I think later on you'll get into command line stuff. 1187 00:42:20,800 --> 00:42:24,770 So for example, instead of me asking you for an integer-- sorry, 1188 00:42:24,770 --> 00:42:26,720 can I speak into you? 1189 00:42:26,720 --> 00:42:27,220 HANNAH: Yes. 1190 00:42:27,220 --> 00:42:30,660 1191 00:42:30,660 --> 00:42:32,450 >> JASON HIRSCHHORN: So for example, instead 1192 00:42:32,450 --> 00:42:35,830 of me asking for something with get end, which 1193 00:42:35,830 --> 00:42:38,854 I think you might have seen a lecture, there might be a command line. 1194 00:42:38,854 --> 00:42:40,520 You just type it in at the command line. 1195 00:42:40,520 --> 00:42:46,690 It would be like -/hello4 or something, or helloh h, whatever. 1196 00:42:46,690 --> 00:42:49,190 You do it at the command line instead of being asked for it, 1197 00:42:49,190 --> 00:42:53,830 that command line is always a string, whether it's a four or an h, 1198 00:42:53,830 --> 00:42:55,320 that is always a string. 1199 00:42:55,320 --> 00:42:59,130 So that's one example of when you might have a singular letter or a singular 1200 00:42:59,130 --> 00:43:00,667 number represented as a string. 1201 00:43:00,667 --> 00:43:06,360 1202 00:43:06,360 --> 00:43:07,110 SHARON: All right. 1203 00:43:07,110 --> 00:43:08,230 1204 00:43:08,230 --> 00:43:09,855 And then here are some basic operators. 1205 00:43:09,855 --> 00:43:11,460 1206 00:43:11,460 --> 00:43:14,560 Hopefully you're familiar with the first four just in general. 1207 00:43:14,560 --> 00:43:18,080 So there's adding, subtracting, multiplying, and dividing, 1208 00:43:18,080 --> 00:43:23,535 and make sure you use the right keystrokes. 1209 00:43:23,535 --> 00:43:25,260 1210 00:43:25,260 --> 00:43:29,640 >> And then there's also modulo, which some of you might not be very familiar with. 1211 00:43:29,640 --> 00:43:34,900 And what modulo does is that if we take this example 4 % 2, 1212 00:43:34,900 --> 00:43:37,990 it takes the remainder of what that does in division. 1213 00:43:37,990 --> 00:43:41,670 So 4 divided by 2 is 2, and there's no remainder. 1214 00:43:41,670 --> 00:43:47,880 4 divide by 3 is 1 and 1/3, and so remainder 1. 1215 00:43:47,880 --> 00:43:49,320 So it computes to one. 1216 00:43:49,320 --> 00:43:56,960 And then 4 % 5 is the fraction 4/5, and the remainder is 4. 1217 00:43:56,960 --> 00:43:58,580 Does that make sense? 1218 00:43:58,580 --> 00:43:59,580 OK, cool. 1219 00:43:59,580 --> 00:44:01,080 1220 00:44:01,080 --> 00:44:03,110 And we follow PEMDAS here too. 1221 00:44:03,110 --> 00:44:06,240 1222 00:44:06,240 --> 00:44:07,740 >> So some Boolean expressions. 1223 00:44:07,740 --> 00:44:08,920 1224 00:44:08,920 --> 00:44:16,890 So you guys have seen equals equals to compare, say, two numbers. 1225 00:44:16,890 --> 00:44:20,440 So if 5 equals equals 5, that computes to true. 1226 00:44:20,440 --> 00:44:22,190 Make sure you have only one equals sign. 1227 00:44:22,190 --> 00:44:23,530 1228 00:44:23,530 --> 00:44:27,030 For not equals, it's bang or exclamation. 1229 00:44:27,030 --> 00:44:28,960 >> HANNAH: Two equal signs when you do equality. 1230 00:44:28,960 --> 00:44:29,290 >> SHARON: Oh, yeah. 1231 00:44:29,290 --> 00:44:30,998 Make sure you don't have one equals sign. 1232 00:44:30,998 --> 00:44:32,320 1233 00:44:32,320 --> 00:44:35,745 And then for not equals, it's bang equals. 1234 00:44:35,745 --> 00:44:37,000 1235 00:44:37,000 --> 00:44:40,540 And then you can look through for less than, greater than. 1236 00:44:40,540 --> 00:44:44,300 And then we have logical and and logical or right here. 1237 00:44:44,300 --> 00:44:47,190 And what that does is, if you remember in Scratch 1238 00:44:47,190 --> 00:44:51,000 when you had that block that said and, and then you 1239 00:44:51,000 --> 00:44:54,860 could fit two different pieces there, that's what this and does. 1240 00:44:54,860 --> 00:44:56,450 And make sure you do two ampersands. 1241 00:44:56,450 --> 00:44:57,590 1242 00:44:57,590 --> 00:45:04,110 And this key you can find towards the right, right under your Delete button. 1243 00:45:04,110 --> 00:45:07,820 1244 00:45:07,820 --> 00:45:08,907 Question? 1245 00:45:08,907 --> 00:45:10,398 >> STUDENT: What was the [INAUDIBLE]? 1246 00:45:10,398 --> 00:45:16,900 1247 00:45:16,900 --> 00:45:20,400 >> SHARON: OK, so if you only do one, you're comparing bits. 1248 00:45:20,400 --> 00:45:22,040 1249 00:45:22,040 --> 00:45:26,400 So if you remember what bits are, they're 0's and 1's, and so 1250 00:45:26,400 --> 00:45:27,740 that's comparing something else. 1251 00:45:27,740 --> 00:45:29,440 So we're going to focus on this for now. 1252 00:45:29,440 --> 00:45:31,856 >> JASON HIRSCHHORN: So one equals is like assignment, right? 1253 00:45:31,856 --> 00:45:33,170 So like int x equals 4. 1254 00:45:33,170 --> 00:45:38,080 You're saying that variable x equals 4. 1255 00:45:38,080 --> 00:45:42,910 So 1 equals is assignment, but the ands and the pipes 1256 00:45:42,910 --> 00:45:45,820 or the bars, just like Sharon said, they're bitwise operators. 1257 00:45:45,820 --> 00:45:47,620 You don't need to worry about that. 1258 00:45:47,620 --> 00:45:49,120 1259 00:45:49,120 --> 00:45:51,620 >> STUDENT: When do you use logical and and logical or again? 1260 00:45:51,620 --> 00:45:54,620 I just forgot when you do that. 1261 00:45:54,620 --> 00:45:57,510 >> HANNAH: Sure, so if you ever want to check if two things are true, 1262 00:45:57,510 --> 00:46:01,550 for example, let's say I want to check that a number is between 5 and 15, 1263 00:46:01,550 --> 00:46:04,660 I would say make sure that the number is greater than 5. 1264 00:46:04,660 --> 00:46:09,430 So let's say if x is greater than 5 and less than 15. 1265 00:46:09,430 --> 00:46:12,630 So in order for that whole statement to evaluate to true, 1266 00:46:12,630 --> 00:46:16,290 you need both of the kind of sub statements to evaluate the true. 1267 00:46:16,290 --> 00:46:18,481 With or you only need one of the two or both. 1268 00:46:18,481 --> 00:46:19,564 STUDENT: Great, thank you. 1269 00:46:19,564 --> 00:46:20,820 1270 00:46:20,820 --> 00:46:24,980 >> SHARON: And also in Scratch, I'm sure in a lot of your projects 1271 00:46:24,980 --> 00:46:31,059 you had if touching the edge or if touching another sprite then bounce 1272 00:46:31,059 --> 00:46:31,600 or something. 1273 00:46:31,600 --> 00:46:34,362 1274 00:46:34,362 --> 00:46:37,070 HANNAH: All right, so why do we care about all of these Booleans? 1275 00:46:37,070 --> 00:46:40,600 We have these structures that you've seen in Scratch called conditionals. 1276 00:46:40,600 --> 00:46:44,830 And conditionals are anything of the form if some condition or some Boolean 1277 00:46:44,830 --> 00:46:48,970 is true, then do the code between these curly braces. 1278 00:46:48,970 --> 00:46:51,220 So you can see on the right here is the Scratch block. 1279 00:46:51,220 --> 00:46:55,132 You have this if then, and anything that goes into that little shape that 1280 00:46:55,132 --> 00:46:56,840 looks like this-- i don't know what you'd 1281 00:46:56,840 --> 00:46:59,960 call that-- that's going to be the Boolean or condition. 1282 00:46:59,960 --> 00:47:01,880 >> So again, a Boolean or condition is anything 1283 00:47:01,880 --> 00:47:04,500 that either evaluate to true or false. 1284 00:47:04,500 --> 00:47:06,150 And again, you can combine Booleans. 1285 00:47:06,150 --> 00:47:10,740 You can have, again, x is greater than 5 and x is less than 15. 1286 00:47:10,740 --> 00:47:13,610 Or you can just have one of those x is less than 5. 1287 00:47:13,610 --> 00:47:16,850 >> OK, so in C It's on the left. 1288 00:47:16,850 --> 00:47:18,270 It's just the keyword if. 1289 00:47:18,270 --> 00:47:20,750 In parentheses, the condition or the Boolean. 1290 00:47:20,750 --> 00:47:23,590 And then the code in between those two curly braces 1291 00:47:23,590 --> 00:47:28,746 will only execute, will only run if that condition or that Boolean is true. 1292 00:47:28,746 --> 00:47:30,385 Does that make sense? 1293 00:47:30,385 --> 00:47:30,885 Awesome. 1294 00:47:30,885 --> 00:47:31,570 OK. 1295 00:47:31,570 --> 00:47:33,278 And then as you may have seen in Scratch, 1296 00:47:33,278 --> 00:47:35,830 we can also add on an else, which is basically 1297 00:47:35,830 --> 00:47:38,820 anything between the curly braces under else 1298 00:47:38,820 --> 00:47:41,430 will only execute if the condition is false. 1299 00:47:41,430 --> 00:47:42,610 1300 00:47:42,610 --> 00:47:43,600 Make sense? 1301 00:47:43,600 --> 00:47:44,840 Any questions on these two? 1302 00:47:44,840 --> 00:47:45,905 1303 00:47:45,905 --> 00:47:46,405 Awesome. 1304 00:47:46,405 --> 00:47:48,430 1305 00:47:48,430 --> 00:47:49,125 >> Cool. 1306 00:47:49,125 --> 00:47:50,650 So here's a quick example. 1307 00:47:50,650 --> 00:47:54,410 Let's say we want to determine, based on the time, 1308 00:47:54,410 --> 00:47:56,760 whether we should say good morning or good evening. 1309 00:47:56,760 --> 00:48:00,480 I'll say if it's before 12:00 noon, we're going to say good morning, 1310 00:48:00,480 --> 00:48:02,940 otherwise we're going to say good evening. 1311 00:48:02,940 --> 00:48:07,180 And when I said that otherwise, that's equivalent in C to this else. 1312 00:48:07,180 --> 00:48:10,580 So we're going to check if the military time is less than 12:00, 1313 00:48:10,580 --> 00:48:12,060 say good morning. 1314 00:48:12,060 --> 00:48:14,025 Otherwise say good evening. 1315 00:48:14,025 --> 00:48:17,500 >> STUDENT: So we'd actually get that input for military time with the get string. 1316 00:48:17,500 --> 00:48:18,097 1317 00:48:18,097 --> 00:48:18,680 HANNAH: Right. 1318 00:48:18,680 --> 00:48:22,110 Did Somewhere else we'd actually have to provide that information. 1319 00:48:22,110 --> 00:48:23,700 Right here it has no value. 1320 00:48:23,700 --> 00:48:25,510 We never even declared it. 1321 00:48:25,510 --> 00:48:28,630 I assume that somewhere above this program I declared the time, 1322 00:48:28,630 --> 00:48:32,090 or asked the time, or-- anything else with this example? 1323 00:48:32,090 --> 00:48:33,560 1324 00:48:33,560 --> 00:48:34,060 Awesome. 1325 00:48:34,060 --> 00:48:35,750 1326 00:48:35,750 --> 00:48:40,490 >> OK, now we have in addition to that simple if else format, 1327 00:48:40,490 --> 00:48:42,899 we have two other different structures. 1328 00:48:42,899 --> 00:48:44,940 So first we have the switch statement, and here's 1329 00:48:44,940 --> 00:48:46,564 the general form of a switch statement. 1330 00:48:46,564 --> 00:48:49,450 1331 00:48:49,450 --> 00:48:53,110 You have the keyword switch the same way you have the keyword if. 1332 00:48:53,110 --> 00:48:56,250 And then an input, in this case n. 1333 00:48:56,250 --> 00:48:58,410 So this can only work with integers. 1334 00:48:58,410 --> 00:49:02,270 So that input n has to be an integer, OK? 1335 00:49:02,270 --> 00:49:04,950 And we're going to follow one of these cases 1336 00:49:04,950 --> 00:49:07,430 depending on what that value n is. 1337 00:49:07,430 --> 00:49:12,170 >> So in this case, you first compare is n equal to constant one, 1338 00:49:12,170 --> 00:49:15,844 if it is, do everything kind of indented over here. 1339 00:49:15,844 --> 00:49:17,510 I can point to it because I'm too short. 1340 00:49:17,510 --> 00:49:19,400 1341 00:49:19,400 --> 00:49:23,210 If it's not equal to constant one and is instead equal to constant two, 1342 00:49:23,210 --> 00:49:27,060 we're going to follow that second block, and we can do this for as many times 1343 00:49:27,060 --> 00:49:32,890 as we want, and then that default is if it didn't match any of the above cases, 1344 00:49:32,890 --> 00:49:33,820 execute that code. 1345 00:49:33,820 --> 00:49:35,759 1346 00:49:35,759 --> 00:49:36,550 Any questions here? 1347 00:49:36,550 --> 00:49:38,133 This one is a little more complicated. 1348 00:49:38,133 --> 00:49:38,633 1349 00:49:38,633 --> 00:49:39,395 Yeah? 1350 00:49:39,395 --> 00:49:41,820 >> STUDENT: Break signifying what? 1351 00:49:41,820 --> 00:49:45,560 >> HANNAH: Sure, so once we enter that block, if we find, let's say, 1352 00:49:45,560 --> 00:49:50,940 our n is in fact equal to constant one, we enter that block after the colon. 1353 00:49:50,940 --> 00:49:54,840 We do whatever is on that line of commenting, 1354 00:49:54,840 --> 00:49:58,182 and then we break, meaning we get out of this switch statement entirely. 1355 00:49:58,182 --> 00:49:58,682 STUDENT: OK. 1356 00:49:58,682 --> 00:49:59,830 1357 00:49:59,830 --> 00:50:00,562 >> HANNAH: Mm-hm? 1358 00:50:00,562 --> 00:50:03,311 >> STUDENT: Is the indentation necessary, or do you need [INAUDIBLE]? 1359 00:50:03,311 --> 00:50:03,959 1360 00:50:03,959 --> 00:50:04,500 HANNAH: Sure. 1361 00:50:04,500 --> 00:50:07,640 So, as always, indentation is not strictly necessary. 1362 00:50:07,640 --> 00:50:09,930 The computer doesn't care whether you indent. 1363 00:50:09,930 --> 00:50:12,630 We, as people who are reading your code, do care. 1364 00:50:12,630 --> 00:50:15,100 So it's a lot easier to look up at the screen 1365 00:50:15,100 --> 00:50:19,707 and see, oh, I know exactly what happens when n is equal to constant one. 1366 00:50:19,707 --> 00:50:22,290 If I had random indents, I wouldn't be able to tell so easily. 1367 00:50:22,290 --> 00:50:23,276 Yeah? 1368 00:50:23,276 --> 00:50:27,466 >> STUDENT: So if wanted a user to choose one of the options that 1369 00:50:27,466 --> 00:50:31,657 we have on the list, would we use, I guess, [INAUDIBLE], 1370 00:50:31,657 --> 00:50:35,108 but get an integer from them and put that into n? 1371 00:50:35,108 --> 00:50:36,844 1372 00:50:36,844 --> 00:50:37,760 HANNAH: Exactly right. 1373 00:50:37,760 --> 00:50:40,330 So let's say we wanted to check what integer. 1374 00:50:40,330 --> 00:50:45,380 We said oh, enter an integer between 0 and 5, let's say. 1375 00:50:45,380 --> 00:50:47,790 We could ask for that n, ask for that value, 1376 00:50:47,790 --> 00:50:50,000 and then have each of those cases. 1377 00:50:50,000 --> 00:50:53,230 And again, this is something we could very easily do with if statements, 1378 00:50:53,230 --> 00:50:53,730 right? 1379 00:50:53,730 --> 00:50:56,920 We could have if equal to case one, if equal to case two, 1380 00:50:56,920 --> 00:50:58,910 if equal to case three, so on and so forth. 1381 00:50:58,910 --> 00:51:01,680 This is a little bit faster and a little cleaner. 1382 00:51:01,680 --> 00:51:04,201 It's kind of just a nice structure now. 1383 00:51:04,201 --> 00:51:05,450 STUDENT: Faster as in writing? 1384 00:51:05,450 --> 00:51:06,830 Or does it run the computer a little faster? 1385 00:51:06,830 --> 00:51:08,246 >> HANNAH: It's runs a little faster. 1386 00:51:08,246 --> 00:51:09,214 1387 00:51:09,214 --> 00:51:09,714 Yeah? 1388 00:51:09,714 --> 00:51:13,490 >> STUDENT: So the double dash is just comment or-- 1389 00:51:13,490 --> 00:51:14,700 >> HANNAH: Oh, I'm so sorry. 1390 00:51:14,700 --> 00:51:15,700 I didn't point that out. 1391 00:51:15,700 --> 00:51:17,790 OK, if you have that //, is a comment. 1392 00:51:17,790 --> 00:51:19,250 1393 00:51:19,250 --> 00:51:20,770 Just // is a comment. 1394 00:51:20,770 --> 00:51:23,030 So any time the computer sees that, it's going 1395 00:51:23,030 --> 00:51:25,760 to say OK, anything that follows this, I'm just going to ignore. 1396 00:51:25,760 --> 00:51:27,310 I'm going to pretend you never even wrote that. 1397 00:51:27,310 --> 00:51:28,850 >> STUDENT: So this [INAUDIBLE]. 1398 00:51:28,850 --> 00:51:30,650 >> HANNAH: This does absolutely nothing. 1399 00:51:30,650 --> 00:51:37,360 But if I wrote something like on the first comment I wrote instead printf 1400 00:51:37,360 --> 00:51:41,640 say congratulations you entered constant one, that would be something. 1401 00:51:41,640 --> 00:51:42,140 Yeah? 1402 00:51:42,140 --> 00:51:44,515 >> STUDENT: So in real life, the case would just simply be a number 1403 00:51:44,515 --> 00:51:46,420 and then [INAUDIBLE] would be another integer. 1404 00:51:46,420 --> 00:51:46,763 >> HANNAH: Exactly. 1405 00:51:46,763 --> 00:51:48,550 >> STUDENT: And do you need the ellipses? 1406 00:51:48,550 --> 00:51:48,805 >> HANNAH: Sorry? 1407 00:51:48,805 --> 00:51:49,550 >> STUDENT: Do you need that? 1408 00:51:49,550 --> 00:51:50,010 >> HANNAH: Oh, no. 1409 00:51:50,010 --> 00:51:50,560 I'm sorry. 1410 00:51:50,560 --> 00:51:53,684 That was just to indicate that you can go on for as many cases as you want. 1411 00:51:53,684 --> 00:51:56,950 Let's do a concrete example that might make things a little more clear. 1412 00:51:56,950 --> 00:52:01,440 OK, so let's say I say, OK, give me an integer n 1413 00:52:01,440 --> 00:52:05,010 that represents a class number, specifically a computer science class 1414 00:52:05,010 --> 00:52:05,720 number. 1415 00:52:05,720 --> 00:52:07,950 So if you give me 50, I'm going to say great. 1416 00:52:07,950 --> 00:52:12,020 CS50 is an introduction to computer science, and then I'm going to break. 1417 00:52:12,020 --> 00:52:14,810 So that means I jump out of this whole switch statement, 1418 00:52:14,810 --> 00:52:17,020 so now I'm done running the code, OK? 1419 00:52:17,020 --> 00:52:21,410 >> If you gave me instead 51, I'd print the second statement. 1420 00:52:21,410 --> 00:52:24,720 And then if you gave me some number that wasn't 50 or 51, 1421 00:52:24,720 --> 00:52:27,133 I'm going to say sorry, I'm not familiar with that class. 1422 00:52:27,133 --> 00:52:28,019 Yeah? 1423 00:52:28,019 --> 00:52:29,350 >> STUDENT: You don't have break. 1424 00:52:29,350 --> 00:52:30,400 >> HANNAH: I'm sorry, I don't have break? 1425 00:52:30,400 --> 00:52:31,510 >> STUDENT: What if. 1426 00:52:31,510 --> 00:52:32,450 >> HANNAH: Oh, what if you don't have break? 1427 00:52:32,450 --> 00:52:33,450 Excellent question. 1428 00:52:33,450 --> 00:52:37,890 So what would happen is you would go in, and you would check am I equal to 50? 1429 00:52:37,890 --> 00:52:42,064 And let's say, yes, you were equal to 50, you'd print the statement. 1430 00:52:42,064 --> 00:52:45,105 And then you would continue executing, so you would say am I equal to 51? 1431 00:52:45,105 --> 00:52:46,500 1432 00:52:46,500 --> 00:52:49,763 And you would go on and go through every case like that? 1433 00:52:49,763 --> 00:52:50,262 Yes? 1434 00:52:50,262 --> 00:52:52,894 >> STUDENT: Is the default line analogous to saying else? 1435 00:52:52,894 --> 00:52:53,560 HANNAH: Exactly. 1436 00:52:53,560 --> 00:52:54,060 Very good. 1437 00:52:54,060 --> 00:52:56,140 It's like the kind of catch all. 1438 00:52:56,140 --> 00:53:00,574 >> STUDENT: So if you didn't have break and then one of the case statements 1439 00:53:00,574 --> 00:53:03,843 was true, and then it said increase n by 1, 1440 00:53:03,843 --> 00:53:09,210 then it would automatically make the next one. 1441 00:53:09,210 --> 00:53:11,657 It would check case 51, and then display that as well? 1442 00:53:11,657 --> 00:53:13,240 HANNAH: Yeah, I think that would work. 1443 00:53:13,240 --> 00:53:15,740 So you could kind of get messy, so a break is a good thing to have. 1444 00:53:15,740 --> 00:53:16,240 Yeah? 1445 00:53:16,240 --> 00:53:18,557 STUDENT: Without break would it do the default? 1446 00:53:18,557 --> 00:53:19,890 HANNAH: That is a good question. 1447 00:53:19,890 --> 00:53:20,590 JASON HIRSCHHORN: I think it just runs. 1448 00:53:20,590 --> 00:53:23,975 So if you don't have break-- so let's say I did 50 and it checked 50, 1449 00:53:23,975 --> 00:53:25,306 and it would print that out. 1450 00:53:25,306 --> 00:53:27,430 Print out CS50 as introduction to computer science. 1451 00:53:27,430 --> 00:53:30,549 You don't have break, it should go and keep going until it hits a break. 1452 00:53:30,549 --> 00:53:32,590 So if there's no break, it's going to keep going. 1453 00:53:32,590 --> 00:53:34,190 It's going to print everything else out. 1454 00:53:34,190 --> 00:53:35,695 >> HANNAH: So I guess that would be including the default. 1455 00:53:35,695 --> 00:53:36,020 >> JASON HIRSCHHORN: Yeah. 1456 00:53:36,020 --> 00:53:36,720 >> HANNAH: Good question. 1457 00:53:36,720 --> 00:53:37,220 Yeah? 1458 00:53:37,220 --> 00:53:39,070 STUDENT: Is case considered a function? 1459 00:53:39,070 --> 00:53:39,820 HANNAH: I'm sorry? 1460 00:53:39,820 --> 00:53:41,570 STUDENT: Is case considered a function? 1461 00:53:41,570 --> 00:53:43,153 HANNAH: Is case considered a function. 1462 00:53:43,153 --> 00:53:45,520 1463 00:53:45,520 --> 00:53:46,840 I would hesitate to say that. 1464 00:53:46,840 --> 00:53:52,000 >> JASON HIRSCHHORN: So normally when you see functions 1465 00:53:52,000 --> 00:53:54,370 they'll be in curly braces. 1466 00:53:54,370 --> 00:53:57,840 So for example, when you look at your code, for example, main. 1467 00:53:57,840 --> 00:54:01,450 It was main open paren, then void, close paren. 1468 00:54:01,450 --> 00:54:05,415 Functions-- they're basically always you'll see parentheses. 1469 00:54:05,415 --> 00:54:07,290 So case if case doesn't have any parentheses, 1470 00:54:07,290 --> 00:54:09,556 that's your clue that that's not a function. 1471 00:54:09,556 --> 00:54:10,984 But it's not. 1472 00:54:10,984 --> 00:54:12,388 1473 00:54:12,388 --> 00:54:12,888 Yeah? 1474 00:54:12,888 --> 00:54:15,280 >> STUDENT: So then does that make switch a function? 1475 00:54:15,280 --> 00:54:16,150 >> HANNAH: Does that makes switch a function. 1476 00:54:16,150 --> 00:54:18,149 >> STUDENT: In the sense that you put something in, 1477 00:54:18,149 --> 00:54:19,399 it gives you one of the cases. 1478 00:54:19,399 --> 00:54:21,399 JASON HIRSCHHORN: I wouldn't call it a function. 1479 00:54:21,399 --> 00:54:23,120 Not everything with parens is a function. 1480 00:54:23,120 --> 00:54:25,629 1481 00:54:25,629 --> 00:54:27,420 I mean that's a clue that it is a function. 1482 00:54:27,420 --> 00:54:30,990 I wouldn't say switch is a function because it's not really 1483 00:54:30,990 --> 00:54:32,207 returning anything. 1484 00:54:32,207 --> 00:54:33,290 You'll get into that more. 1485 00:54:33,290 --> 00:54:34,380 1486 00:54:34,380 --> 00:54:36,476 >> HANNAH: Yeah, just think of it as an if structure. 1487 00:54:36,476 --> 00:54:38,392 STUDENT: Can you nest this in an if structure? 1488 00:54:38,392 --> 00:54:40,197 1489 00:54:40,197 --> 00:54:42,030 HANNAH: Yeah, you nest pretty much anything. 1490 00:54:42,030 --> 00:54:43,170 1491 00:54:43,170 --> 00:54:46,138 >> STUDENT: Barry said the quotes are sort of like the same as else. 1492 00:54:46,138 --> 00:54:48,428 So can you replace the quotes with else? 1493 00:54:48,428 --> 00:54:49,750 1494 00:54:49,750 --> 00:54:52,510 >> HANNAH: Not in this particular structure because the switch 1495 00:54:52,510 --> 00:54:55,250 statement is expecting the word default. 1496 00:54:55,250 --> 00:54:58,427 The computer knows that default means something special, that 1497 00:54:58,427 --> 00:54:59,260 means the catch all. 1498 00:54:59,260 --> 00:55:00,344 1499 00:55:00,344 --> 00:55:01,260 Anything else on this. 1500 00:55:01,260 --> 00:55:02,750 We have one more to get through. 1501 00:55:02,750 --> 00:55:03,654 Yeah? 1502 00:55:03,654 --> 00:55:04,529 >> STUDENT: [INAUDIBLE]. 1503 00:55:04,529 --> 00:55:06,246 1504 00:55:06,246 --> 00:55:08,620 HANNAH: Difference between using a semicolon and a colon. 1505 00:55:08,620 --> 00:55:13,090 So a semicolon is always to tell the computer I am done with this line. 1506 00:55:13,090 --> 00:55:14,440 You can go ahead and execute it. 1507 00:55:14,440 --> 00:55:15,940 This is a complete line. 1508 00:55:15,940 --> 00:55:20,270 A colon is going to, in this case, bring you into a particular block. 1509 00:55:20,270 --> 00:55:21,510 1510 00:55:21,510 --> 00:55:23,790 So semicolons are always use to end lines. 1511 00:55:23,790 --> 00:55:26,603 Colons are used for a variety of other cases. 1512 00:55:26,603 --> 00:55:30,547 >> STUDENT: Is this equivalent to just saying if n equals 50, then 1513 00:55:30,547 --> 00:55:31,443 blah blah blah. 1514 00:55:31,443 --> 00:55:32,026 HANNAH: Mm-hm. 1515 00:55:32,026 --> 00:55:33,998 STUDENT: It's just the same [INAUDIBLE]. 1516 00:55:33,998 --> 00:55:34,804 1517 00:55:34,804 --> 00:55:35,470 HANNAH: Exactly. 1518 00:55:35,470 --> 00:55:37,870 And we said it runs a little bit faster. 1519 00:55:37,870 --> 00:55:41,510 If we did not have the break, it would be like if, if, if. 1520 00:55:41,510 --> 00:55:45,406 If we do have the break, it's like if else if else if else if. 1521 00:55:45,406 --> 00:55:47,340 1522 00:55:47,340 --> 00:55:47,840 Cool? 1523 00:55:47,840 --> 00:55:50,298 >> JASON HIRSCHHORN: So when coding, you can just use if else, 1524 00:55:50,298 --> 00:55:54,000 but I think last year on the quiz we had them write a switch statement, 1525 00:55:54,000 --> 00:55:54,700 so just in case. 1526 00:55:54,700 --> 00:55:56,339 1527 00:55:56,339 --> 00:55:57,880 HANNAH: But definitely nothing wrong. 1528 00:55:57,880 --> 00:56:00,820 We're not expecting you to worry about performance crazy things. 1529 00:56:00,820 --> 00:56:02,780 Just if else is totally fine. 1530 00:56:02,780 --> 00:56:04,530 These are just good things to be aware of. 1531 00:56:04,530 --> 00:56:07,770 >> And here's our last one that kind of falls under this conditional category. 1532 00:56:07,770 --> 00:56:08,970 1533 00:56:08,970 --> 00:56:12,810 We have something of the general form condition ?, 1534 00:56:12,810 --> 00:56:16,350 and then a little piece of code that happens if the condition is true. 1535 00:56:16,350 --> 00:56:18,780 And then colon, a little piece of code that 1536 00:56:18,780 --> 00:56:21,270 executes if the condition is false, semicolon. 1537 00:56:21,270 --> 00:56:22,504 We're done with that line. 1538 00:56:22,504 --> 00:56:24,170 So syntactically it's a little bit ugly. 1539 00:56:24,170 --> 00:56:26,850 We're going to go through an example I think that's most clear. 1540 00:56:26,850 --> 00:56:31,420 So we want to assign the string professor 1541 00:56:31,420 --> 00:56:35,900 to one of these two values, either David Malan or not David Malan, OK? 1542 00:56:35,900 --> 00:56:38,740 So you should be familiar with the string, professor =. 1543 00:56:38,740 --> 00:56:41,770 We're going to assign a string to the variable called professor. 1544 00:56:41,770 --> 00:56:43,440 1545 00:56:43,440 --> 00:56:46,360 >> Now we want to check a particular condition. 1546 00:56:46,360 --> 00:56:50,700 In this case, our condition is class_num = = 50. 1547 00:56:50,700 --> 00:56:53,080 And now might be a good time to point out 1548 00:56:53,080 --> 00:56:56,500 when we have string professor =, that's one equals sign. 1549 00:56:56,500 --> 00:56:57,870 That's assignment. 1550 00:56:57,870 --> 00:57:01,360 Whereas in class_num = = 50, that's two equal signs. 1551 00:57:01,360 --> 00:57:03,050 That's a quality check. 1552 00:57:03,050 --> 00:57:06,000 So we're going to say is the class number equal to 50? 1553 00:57:06,000 --> 00:57:10,060 If so, assign Professor David Malan. 1554 00:57:10,060 --> 00:57:13,710 If not, assign professor to not David Malan. 1555 00:57:13,710 --> 00:57:15,320 1556 00:57:15,320 --> 00:57:16,327 Any questions there? 1557 00:57:16,327 --> 00:57:18,410 Again, this is just something that's good to know. 1558 00:57:18,410 --> 00:57:20,230 You could do this with if else. 1559 00:57:20,230 --> 00:57:22,550 A good practice problem might be to, when 1560 00:57:22,550 --> 00:57:27,830 you go home, right the same exact conditional in an if else form, 1561 00:57:27,830 --> 00:57:28,830 because you can do that. 1562 00:57:28,830 --> 00:57:29,950 1563 00:57:29,950 --> 00:57:30,785 Any questions here? 1564 00:57:30,785 --> 00:57:31,829 1565 00:57:31,829 --> 00:57:33,870 All right, I think we're going to go on to loops. 1566 00:57:33,870 --> 00:57:34,881 1567 00:57:34,881 --> 00:57:35,380 Awesome. 1568 00:57:35,380 --> 00:57:36,780 1569 00:57:36,780 --> 00:57:38,730 >> SHARON: OK, let's talk about while loops. 1570 00:57:38,730 --> 00:57:49,995 So first on the left you see here-- OK that says while, while (condition). 1571 00:57:49,995 --> 00:57:51,040 1572 00:57:51,040 --> 00:57:53,142 And then you do this-- can we change this? 1573 00:57:53,142 --> 00:57:54,433 >> JASON HIRSCHHORN: It's cut off. 1574 00:57:54,433 --> 00:57:55,420 1575 00:57:55,420 --> 00:57:58,010 >> SHARON: OK, and then there are also curly braces. 1576 00:57:58,010 --> 00:58:01,680 So pretend that curly braces are there above 1577 00:58:01,680 --> 00:58:04,070 and below the do this again and again. 1578 00:58:04,070 --> 00:58:10,930 So if the condition in those parentheses evaluates to true, 1579 00:58:10,930 --> 00:58:15,150 then you should keep doing whatever is in the while loop. 1580 00:58:15,150 --> 00:58:19,610 >> So for example, we could do a practice problem. 1581 00:58:19,610 --> 00:58:20,760 1582 00:58:20,760 --> 00:58:23,750 I'm wearing two earrings right now, so let's say 1583 00:58:23,750 --> 00:58:27,580 if I'm wearing at least one hearing, clap your hands. 1584 00:58:27,580 --> 00:58:30,060 So if we're going to go through this, we're going-- 1585 00:58:30,060 --> 00:58:30,790 >> [CLAPPING] 1586 00:58:30,790 --> 00:58:31,930 >> Right? 1587 00:58:31,930 --> 00:58:36,710 And I'm wearing one, and-- OK. 1588 00:58:36,710 --> 00:58:37,300 Yeah. 1589 00:58:37,300 --> 00:58:39,850 I'm not wearing earrings anymore, so no more. 1590 00:58:39,850 --> 00:58:41,980 OK, so then that's when you would stop. 1591 00:58:41,980 --> 00:58:45,980 And this you could say is equivalent to almost variables. 1592 00:58:45,980 --> 00:58:50,190 Let's say you have a variable number of earrings. 1593 00:58:50,190 --> 00:58:51,660 1594 00:58:51,660 --> 00:59:00,940 So while number of earrings is greater than or equal to 1, clap hands. 1595 00:59:00,940 --> 00:59:08,310 And then after clap hands, decrement earrings. 1596 00:59:08,310 --> 00:59:11,060 Do like earrings minus 1. 1597 00:59:11,060 --> 00:59:15,205 So decrement the number of earrings, and then you will go through the while loop 1598 00:59:15,205 --> 00:59:16,300 twice. 1599 00:59:16,300 --> 00:59:24,780 >> And if the condition is always true-- so if, let's say, 2 = = 2, 1600 00:59:24,780 --> 00:59:28,670 and 2 is always equal to 2, right? 1601 00:59:28,670 --> 00:59:30,780 Then you would always do something in there, 1602 00:59:30,780 --> 00:59:35,500 and that's equivalent to almost the forever loop that we had in Scratch. 1603 00:59:35,500 --> 00:59:36,865 1604 00:59:36,865 --> 00:59:37,364 Yes? 1605 00:59:37,364 --> 00:59:41,100 >> STUDENT: Are the two sides just different ways of writing a while loop? 1606 00:59:41,100 --> 00:59:43,100 >> SHARON: So we're focused on this one first. 1607 00:59:43,100 --> 00:59:45,520 And then so let's compare it with a do while loop. 1608 00:59:45,520 --> 00:59:47,460 So they're slightly different. 1609 00:59:47,460 --> 00:59:54,120 OK, so let's say the condition is still while I'm wearing at least one earring, 1610 00:59:54,120 --> 00:59:56,410 and I'm not wearing any earrings right now. 1611 00:59:56,410 --> 01:00:01,860 And let's say do and still clap while I'm wearing at least one earring. 1612 01:00:01,860 --> 01:00:02,850 What should happen? 1613 01:00:02,850 --> 01:00:04,236 >> [CLAPS] 1614 01:00:04,236 --> 01:00:06,210 >> Uh oh, guys. 1615 01:00:06,210 --> 01:00:11,820 OK, so you're supposed to clap once because basically you 1616 01:00:11,820 --> 01:00:13,510 go through the first part of the code. 1617 01:00:13,510 --> 01:00:18,630 You do it no matter what, and then you see the while condition, 1618 01:00:18,630 --> 01:00:22,640 and you go back into that loop if it's true. 1619 01:00:22,640 --> 01:00:23,969 1620 01:00:23,969 --> 01:00:24,885 Does that makes sense? 1621 01:00:24,885 --> 01:00:26,593 >> STUDENT: You always do it the first time. 1622 01:00:26,593 --> 01:00:29,810 SHARON: You always do it the first time regardless of whether 1623 01:00:29,810 --> 01:00:31,659 or not that condition is true or not. 1624 01:00:31,659 --> 01:00:33,950 JASON HIRSCHHORN: When do you think you could use this? 1625 01:00:33,950 --> 01:00:35,480 When does it make sense to use this? 1626 01:00:35,480 --> 01:00:36,839 1627 01:00:36,839 --> 01:00:37,380 HANNAH: Yeah? 1628 01:00:37,380 --> 01:00:38,255 STUDENT: [INAUDIBLE]. 1629 01:00:38,255 --> 01:00:40,080 1630 01:00:40,080 --> 01:00:41,080 JASON HIRSCHHORN: Right. 1631 01:00:41,080 --> 01:00:41,575 HANNAH: Very good. 1632 01:00:41,575 --> 01:00:43,408 JASON HIRSCHHORN: So when you prompt a user, 1633 01:00:43,408 --> 01:00:45,947 you're going to always want to prompt a user one time. 1634 01:00:45,947 --> 01:00:48,280 You're always going to want to prompt the user one time. 1635 01:00:48,280 --> 01:00:50,103 So instead of putting in a while loop, you 1636 01:00:50,103 --> 01:00:52,820 put in do while loop, because you're always going to do it one time. 1637 01:00:52,820 --> 01:00:54,730 If they give you the correct answer, you're done. 1638 01:00:54,730 --> 01:00:56,355 If they don't, then you re-prompt them. 1639 01:00:56,355 --> 01:01:02,080 1640 01:01:02,080 --> 01:01:03,360 >> SHARON: All right, for loops. 1641 01:01:03,360 --> 01:01:05,830 1642 01:01:05,830 --> 01:01:08,590 So in Scratch, we had repeat blocks. 1643 01:01:08,590 --> 01:01:12,640 So we wanted to repeat something, let's say, seven times. 1644 01:01:12,640 --> 01:01:16,580 So we just said repeat seven, and say I'm here to help you Snow White! 1645 01:01:16,580 --> 01:01:18,590 1646 01:01:18,590 --> 01:01:22,550 In C, we have for loops if we want to go through something 1647 01:01:22,550 --> 01:01:23,970 a specific number of times. 1648 01:01:23,970 --> 01:01:29,700 Let's say if we initialize the variable dwarves 1649 01:01:29,700 --> 01:01:35,410 and make sure-- so the first block right there before the first semicolon, 1650 01:01:35,410 --> 01:01:39,260 we initialize our variable to, and we set it to 0. 1651 01:01:39,260 --> 01:01:41,850 And our variable there is an integer, int. 1652 01:01:41,850 --> 01:01:43,590 1653 01:01:43,590 --> 01:01:47,640 And the variable name is dwarves, and we set dwarves to 0. 1654 01:01:47,640 --> 01:01:52,660 >> And the second part between the two semicolons is our condition. 1655 01:01:52,660 --> 01:01:53,720 1656 01:01:53,720 --> 01:01:58,630 And so as long as dwarves is less than seven, 1657 01:01:58,630 --> 01:02:01,730 we'll keep going through this for loop. 1658 01:02:01,730 --> 01:02:06,350 And then the last part is what do we do at the end of this for loop? 1659 01:02:06,350 --> 01:02:12,480 dwarves ++, and that means we increment dwarves by one every time. 1660 01:02:12,480 --> 01:02:13,900 >> So what's going to happen here? 1661 01:02:13,900 --> 01:02:15,860 1662 01:02:15,860 --> 01:02:17,620 So first we're going to go through. 1663 01:02:17,620 --> 01:02:19,690 We have dwarves as 0, and then we're going 1664 01:02:19,690 --> 01:02:22,845 to print I'm here to help you Snow White! 1665 01:02:22,845 --> 01:02:24,120 1666 01:02:24,120 --> 01:02:27,197 And then dwarves is going to increase because we said dwarves ++. 1667 01:02:27,197 --> 01:02:28,409 1668 01:02:28,409 --> 01:02:29,450 Dwarves is going to be 1. 1669 01:02:29,450 --> 01:02:32,720 And then we compare-- dwarves is 1. 1670 01:02:32,720 --> 01:02:35,900 We compare it to is dwarves less than 7? 1671 01:02:35,900 --> 01:02:36,660 Yes. 1672 01:02:36,660 --> 01:02:38,320 I'm going to go through this again. 1673 01:02:38,320 --> 01:02:40,190 I'm here to help you Snow White! 1674 01:02:40,190 --> 01:02:44,490 And then dwarves becomes 2, and then we compare it. 1675 01:02:44,490 --> 01:02:46,621 Is 2 less that 7? 1676 01:02:46,621 --> 01:02:47,120 Yes. 1677 01:02:47,120 --> 01:02:48,740 We're going to keep going through. 1678 01:02:48,740 --> 01:02:51,395 And we're going to go through this seven times. 1679 01:02:51,395 --> 01:02:52,980 1680 01:02:52,980 --> 01:02:59,290 >> So in the end, we're going to have dwarves = 0 print out I'm 1681 01:02:59,290 --> 01:03:00,710 here to help you Snow White! 1682 01:03:00,710 --> 01:03:04,810 dwarves equals 1, 2, 3, 4, 5, and 6. 1683 01:03:04,810 --> 01:03:07,280 Remember we index at 0. 1684 01:03:07,280 --> 01:03:08,546 So we start with 0. 1685 01:03:08,546 --> 01:03:09,046 Yes? 1686 01:03:09,046 --> 01:03:11,630 >> STUDENT: So this is different than the do 1687 01:03:11,630 --> 01:03:13,920 because this doesn't print out initially at first. 1688 01:03:13,920 --> 01:03:15,880 So you could continue the same thing. 1689 01:03:15,880 --> 01:03:17,220 1690 01:03:17,220 --> 01:03:19,095 Could you do this also with the do loop? 1691 01:03:19,095 --> 01:03:20,450 Like the same process. 1692 01:03:20,450 --> 01:03:24,175 The condition is dwarves less than 7 or whatever. 1693 01:03:24,175 --> 01:03:25,961 Response is less than 7. 1694 01:03:25,961 --> 01:03:27,335 SHARON: So you could technically. 1695 01:03:27,335 --> 01:03:30,360 1696 01:03:30,360 --> 01:03:34,210 So if we go back to-- your talking about the while loop, right? 1697 01:03:34,210 --> 01:03:36,010 So the do while loop is slightly different 1698 01:03:36,010 --> 01:03:39,966 because we guarantee at least once that we'll go through it, 1699 01:03:39,966 --> 01:03:41,340 so that's the biggest difference. 1700 01:03:41,340 --> 01:03:50,330 But with the while loop we could say while dwarves is less than 7, 1701 01:03:50,330 --> 01:03:53,310 do this, and then increment dwarves by one. 1702 01:03:53,310 --> 01:03:58,660 And then we have to initialize dwarves before this whole statement 1703 01:03:58,660 --> 01:04:00,628 that it equals 0. 1704 01:04:00,628 --> 01:04:02,128 So yeah, we could do that with that. 1705 01:04:02,128 --> 01:04:03,104 Mm-hm? 1706 01:04:03,104 --> 01:04:05,056 >> STUDENT: Can you go back to [INAUDIBLE]? 1707 01:04:05,056 --> 01:04:06,827 1708 01:04:06,827 --> 01:04:07,535 SHARON: For loop? 1709 01:04:07,535 --> 01:04:13,266 STUDENT: Yeah, so with the dwarves ++, seems like that's what you do after 1710 01:04:13,266 --> 01:04:15,440 you've ran some other means. 1711 01:04:15,440 --> 01:04:16,106 SHARON: Correct. 1712 01:04:16,106 --> 01:04:18,380 STUDENT: Could you just not have that and put it-- 1713 01:04:18,380 --> 01:04:19,130 SHARON: You could. 1714 01:04:19,130 --> 01:04:23,770 STUDENT: So is [INAUDIBLE] right after print out in the next line underneath. 1715 01:04:23,770 --> 01:04:25,430 SHARON: Yes, you could put it there. 1716 01:04:25,430 --> 01:04:27,952 But then you would just leave that empty. 1717 01:04:27,952 --> 01:04:31,090 >> JASON HIRSCHHORN: You still need the semi colon though. 1718 01:04:31,090 --> 01:04:34,194 >> SHARON: It looks a little awkward, but you could technically do that. 1719 01:04:34,194 --> 01:04:35,118 Technically. 1720 01:04:35,118 --> 01:04:35,840 Please don't. 1721 01:04:35,840 --> 01:04:37,295 1722 01:04:37,295 --> 01:04:38,265 Yes? 1723 01:04:38,265 --> 01:04:40,687 >> STUDENT: Are there any alternatives to ++? 1724 01:04:40,687 --> 01:04:42,145 Is there anything else [INAUDIBLE]? 1725 01:04:42,145 --> 01:04:52,990 1726 01:04:52,990 --> 01:04:54,825 >> SHARON: Technically it it's dwarves. 1727 01:04:54,825 --> 01:04:56,880 1728 01:04:56,880 --> 01:05:01,680 One equals sign we're going to set it to dwarves plus 1. 1729 01:05:01,680 --> 01:05:03,670 1730 01:05:03,670 --> 01:05:06,762 So technically that's what dwarves ++ means. 1731 01:05:06,762 --> 01:05:07,685 Does that make sense? 1732 01:05:07,685 --> 01:05:09,601 >> STUDENT: Yeah, but are there any alternatives? 1733 01:05:09,601 --> 01:05:10,830 Like if you ever-- 1734 01:05:10,830 --> 01:05:13,130 >> SHARON: Yeah, you could do dwarves - -. 1735 01:05:13,130 --> 01:05:14,280 >> STUDENT: [INAUDIBLE]. 1736 01:05:14,280 --> 01:05:16,299 >> SHARON: Yeah, you could do a host of things. 1737 01:05:16,299 --> 01:05:17,840 HANNAH: And you could increment by 2. 1738 01:05:17,840 --> 01:05:19,690 You could increment by 3. 1739 01:05:19,690 --> 01:05:23,120 Anything that's going to be changing, it will eventually make the condition. 1740 01:05:23,120 --> 01:05:26,036 >> STUDENT: So if you wanted to increment by 2, how would you write that? 1741 01:05:26,036 --> 01:05:27,060 1742 01:05:27,060 --> 01:05:31,400 >> HANNAH: You could either write dwarves-- you could write this whole thing out. 1743 01:05:31,400 --> 01:05:32,960 dwarves = dwarves + 2. 1744 01:05:32,960 --> 01:05:34,105 Or a slightly shorthand. 1745 01:05:34,105 --> 01:05:39,893 I'm just going to write + equals 2. 1746 01:05:39,893 --> 01:05:42,784 >> STUDENT: OK, and you'd write that right where dwarves ++ is there. 1747 01:05:42,784 --> 01:05:43,450 HANNAH: Exactly. 1748 01:05:43,450 --> 01:05:44,116 SHARON: Correct. 1749 01:05:44,116 --> 01:05:45,297 1750 01:05:45,297 --> 01:05:46,421 There was another question? 1751 01:05:46,421 --> 01:05:47,383 Yeah? 1752 01:05:47,383 --> 01:05:49,788 >> STUDENT: [INAUDIBLE] dwarves ++? 1753 01:05:49,788 --> 01:05:52,484 1754 01:05:52,484 --> 01:05:53,400 SHARON: So you don't-- 1755 01:05:53,400 --> 01:05:55,430 JASON HIRSCHHORN: Yeah, don't need it there. [INAUDIBLE] very end. 1756 01:05:55,430 --> 01:05:57,250 So you do [INAUDIBLE] ones because you're 1757 01:05:57,250 --> 01:06:01,810 kind of splitting up the initialization, condition, and the change. 1758 01:06:01,810 --> 01:06:03,781 At the very end, you don't need it. 1759 01:06:03,781 --> 01:06:05,780 SHARON: Also notice you don't need the semicolon 1760 01:06:05,780 --> 01:06:07,599 after the whole entire for loop. 1761 01:06:07,599 --> 01:06:09,531 1762 01:06:09,531 --> 01:06:14,361 >> STUDENT: How would you start with an initial number of negative, 1763 01:06:14,361 --> 01:06:16,300 for example? 1764 01:06:16,300 --> 01:06:19,482 >> SHARON: You can initialize dwarves equal to negative 2. 1765 01:06:19,482 --> 01:06:22,140 >> STUDENT: Do you just do dash 2? 1766 01:06:22,140 --> 01:06:24,270 >> SHARON: Yes, so the negative sign, dash 2. 1767 01:06:24,270 --> 01:06:25,976 1768 01:06:25,976 --> 01:06:29,680 >> STUDENT: Is it [INAUDIBLE] to initialize as dwarves [INAUDIBLE]? 1769 01:06:29,680 --> 01:06:30,340 >> SHARON: Yes. 1770 01:06:30,340 --> 01:06:35,630 So if we had just initialized dwarves earlier, just do int dwarves semicolon, 1771 01:06:35,630 --> 01:06:39,300 and then there we can do dwarves set that equal to 0. 1772 01:06:39,300 --> 01:06:43,184 >> STUDENT: Could we do it earlier in the program saying int dwarves = 0, 1773 01:06:43,184 --> 01:06:44,590 and then just-- 1774 01:06:44,590 --> 01:06:46,990 >> SHARON: Just not have-- so there would be a space again, 1775 01:06:46,990 --> 01:06:48,531 but you would still need a semicolon. 1776 01:06:48,531 --> 01:06:49,500 1777 01:06:49,500 --> 01:06:50,890 Yeah. 1778 01:06:50,890 --> 01:06:51,494 Mm-hm? 1779 01:06:51,494 --> 01:06:54,285 STUDENT: Does this code say what the value of dwarves is afterward. 1780 01:06:54,285 --> 01:06:58,030 If you ask it after all of this is done to print the value of dwarves. 1781 01:06:58,030 --> 01:06:59,530 SHARON: You could ask it to do that. 1782 01:06:59,530 --> 01:07:00,191 STUDENT: OK. 1783 01:07:00,191 --> 01:07:02,190 SHARON: But you would have to ask it to do that. 1784 01:07:02,190 --> 01:07:03,231 It doesn't do it for you. 1785 01:07:03,231 --> 01:07:04,730 1786 01:07:04,730 --> 01:07:06,875 I'm scared to put my earrings back in. 1787 01:07:06,875 --> 01:07:07,874 1788 01:07:07,874 --> 01:07:09,290 Do it at the end for the applause. 1789 01:07:09,290 --> 01:07:10,090 Just kidding. 1790 01:07:10,090 --> 01:07:11,755 >> JASON HIRSCHHORN: So that's the same. 1791 01:07:11,755 --> 01:07:13,460 So initialize at the top. 1792 01:07:13,460 --> 01:07:15,360 Condition, print, change. 1793 01:07:15,360 --> 01:07:22,482 So this is exactly the same as that if anybody can see that. 1794 01:07:22,482 --> 01:07:23,871 1795 01:07:23,871 --> 01:07:26,370 STUDENT: Why don't you have the semicolon on the first line? 1796 01:07:26,370 --> 01:07:27,657 1797 01:07:27,657 --> 01:07:28,240 SHARON: Where? 1798 01:07:28,240 --> 01:07:29,490 STUDENT: After the first line. 1799 01:07:29,490 --> 01:07:31,976 SHARON: After the 4 in the parentheses? 1800 01:07:31,976 --> 01:07:33,850 Because we want to go through into this loop. 1801 01:07:33,850 --> 01:07:39,309 And if you take a look at loops in general, they don't have semicolons. 1802 01:07:39,309 --> 01:07:40,100 It's not practical. 1803 01:07:40,100 --> 01:07:45,160 1804 01:07:45,160 --> 01:07:46,240 Are we good? 1805 01:07:46,240 --> 01:07:47,470 One more question, two more. 1806 01:07:47,470 --> 01:07:48,056 Yeah? 1807 01:07:48,056 --> 01:07:49,930 STUDENT: This might be a little bit advanced, 1808 01:07:49,930 --> 01:07:52,840 but do dwarves have a different [INAUDIBLE] 1809 01:07:52,840 --> 01:07:54,780 from a variable [INAUDIBLE]. 1810 01:07:54,780 --> 01:07:57,421 1811 01:07:57,421 --> 01:07:58,170 SHARON: Very good. 1812 01:07:58,170 --> 01:07:59,045 STUDENT: [INAUDIBLE]. 1813 01:07:59,045 --> 01:08:00,480 1814 01:08:00,480 --> 01:08:02,456 >> SHARON: Yes, it is. 1815 01:08:02,456 --> 01:08:03,794 1816 01:08:03,794 --> 01:08:04,422 What? 1817 01:08:04,422 --> 01:08:05,880 JASON HIRSCHHORN: Yeah, so it does. 1818 01:08:05,880 --> 01:08:08,965 So normally the scope of something is in the curly braces. 1819 01:08:08,965 --> 01:08:10,216 1820 01:08:10,216 --> 01:08:12,340 So scope is always going to be in the curly braces, 1821 01:08:12,340 --> 01:08:14,850 but that wouldn't make much sense for the for loop 1822 01:08:14,850 --> 01:08:17,550 because we initialized dwarves in that curly brace. 1823 01:08:17,550 --> 01:08:23,310 So normally the scope of dwarves, that variable wouldn't extend past that. 1824 01:08:23,310 --> 01:08:25,000 This is a special case though. 1825 01:08:25,000 --> 01:08:28,080 So you initialize it within those parentheses, 1826 01:08:28,080 --> 01:08:30,600 and then you have the scope later on. 1827 01:08:30,600 --> 01:08:32,720 So special case. 1828 01:08:32,720 --> 01:08:39,059 They should not have that, and that was-- That make sense? 1829 01:08:39,059 --> 01:08:40,037 >> STUDENT: No. 1830 01:08:40,037 --> 01:08:41,629 >> JASON HIRSCHHORN: I can go over it. 1831 01:08:41,629 --> 01:08:43,170 So what are you still confused about? 1832 01:08:43,170 --> 01:08:47,200 >> STUDENT: As in can you use dwarves-- you can obviously use dwarves [INAUDIBLE] 1833 01:08:47,200 --> 01:08:48,439 outside the formula too? 1834 01:08:48,439 --> 01:08:49,480 >> JASON HIRSCHHORN: No, no. 1835 01:08:49,480 --> 01:08:53,385 So the scope of it is only inside the curly braces for the for loop, yeah. 1836 01:08:53,385 --> 01:08:56,509 1837 01:08:56,509 --> 01:08:59,300 SHARON: But if you initialize dwarves outside of the for loop, then 1838 01:08:59,300 --> 01:09:05,021 you can use it elsewhere There's one more question? 1839 01:09:05,021 --> 01:09:05,520 No? 1840 01:09:05,520 --> 01:09:09,529 1841 01:09:09,529 --> 01:09:10,130 OK. 1842 01:09:10,130 --> 01:09:15,807 >> So we talked a little bit about nesting for loops or nesting conditionals, 1843 01:09:15,807 --> 01:09:16,390 if statements. 1844 01:09:16,390 --> 01:09:17,660 1845 01:09:17,660 --> 01:09:21,310 So here's an example of where we could nest a for loop. 1846 01:09:21,310 --> 01:09:26,500 Let's say we were printing this table of x's right here. 1847 01:09:26,500 --> 01:09:31,430 We might want to-- first if we just don't look at the code 1848 01:09:31,430 --> 01:09:34,329 and we just think about it, we want to go through every row 1849 01:09:34,329 --> 01:09:36,550 and print each column, right? 1850 01:09:36,550 --> 01:09:37,854 1851 01:09:37,854 --> 01:09:38,729 Does that make sense? 1852 01:09:38,729 --> 01:09:39,787 1853 01:09:39,787 --> 01:09:40,286 OK. 1854 01:09:40,286 --> 01:09:41,439 1855 01:09:41,439 --> 01:09:44,809 >> So here we're going through every row for basically each row, 1856 01:09:44,809 --> 01:09:45,850 and there are three rows. 1857 01:09:45,850 --> 01:09:47,149 1858 01:09:47,149 --> 01:09:50,806 And then within each row for each column, and there 1859 01:09:50,806 --> 01:09:53,149 are four columns, print an x. 1860 01:09:53,149 --> 01:09:55,920 1861 01:09:55,920 --> 01:09:56,420 so. 1862 01:09:56,420 --> 01:10:02,400 When row is 0 and column is 0, we print this x. 1863 01:10:02,400 --> 01:10:06,920 And then we keep going through the column loop. 1864 01:10:06,920 --> 01:10:08,300 1865 01:10:08,300 --> 01:10:11,280 Row is still 0, but column is one. 1866 01:10:11,280 --> 01:10:13,760 And then column is 2, and then column is 3. 1867 01:10:13,760 --> 01:10:14,770 1868 01:10:14,770 --> 01:10:19,270 And then we exit out of that loop because then column 1869 01:10:19,270 --> 01:10:20,605 is no longer less than 4. 1870 01:10:20,605 --> 01:10:21,970 1871 01:10:21,970 --> 01:10:25,330 And then we print a new line, and we go to the new line. 1872 01:10:25,330 --> 01:10:30,160 And then we go through the next row, and row gets incremented, 1873 01:10:30,160 --> 01:10:31,885 and we go through that again. 1874 01:10:31,885 --> 01:10:32,760 Does that make sense? 1875 01:10:32,760 --> 01:10:34,120 1876 01:10:34,120 --> 01:10:34,778 Yes? 1877 01:10:34,778 --> 01:10:40,150 >> STUDENT: So to nest [INAUDIBLE] is just putting it inside of the for loop? 1878 01:10:40,150 --> 01:10:44,290 >> SHARON: So nesting means that we have a for loop within a for loop, 1879 01:10:44,290 --> 01:10:45,382 like Inception. 1880 01:10:45,382 --> 01:10:47,798 >> STUDENT: You don't need a special rotation or anything? 1881 01:10:47,798 --> 01:10:49,567 You just stick it right inside of it? 1882 01:10:49,567 --> 01:10:50,233 SHARON: Correct. 1883 01:10:50,233 --> 01:10:52,060 1884 01:10:52,060 --> 01:10:52,560 Yes? 1885 01:10:52,560 --> 01:10:56,050 >> STUDENT: Might be [INAUDIBLE], but it looks like there's an extra space 1886 01:10:56,050 --> 01:10:57,730 between all the x's. 1887 01:10:57,730 --> 01:11:01,197 I don't know if that's-- If that were to actually do the program, 1888 01:11:01,197 --> 01:11:02,530 would it do something like that? 1889 01:11:02,530 --> 01:11:03,320 >> SHARON: So no. 1890 01:11:03,320 --> 01:11:04,970 That was pressing Enter. 1891 01:11:04,970 --> 01:11:06,360 1892 01:11:06,360 --> 01:11:08,342 That was bad on our part. 1893 01:11:08,342 --> 01:11:08,842 Apologize. 1894 01:11:08,842 --> 01:11:11,576 >> HANNAH: How would you change this program if you did one extra line? 1895 01:11:11,576 --> 01:11:12,451 >> STUDENT: [INAUDIBLE]. 1896 01:11:12,451 --> 01:11:13,932 1897 01:11:13,932 --> 01:11:14,640 SHARON: Good job. 1898 01:11:14,640 --> 01:11:16,067 1899 01:11:16,067 --> 01:11:19,150 STUDENT: You can also print the same thing by switching around the column, 1900 01:11:19,150 --> 01:11:20,632 right? 1901 01:11:20,632 --> 01:11:21,620 >> SHARON: Hm? 1902 01:11:21,620 --> 01:11:27,054 >> STUDENT: So to print your little xxx, the first line can say print, 1903 01:11:27,054 --> 01:11:30,020 and instead of saying row, it says column. 1904 01:11:30,020 --> 01:11:32,710 >> SHARON: So you could change the variable names to do that. 1905 01:11:32,710 --> 01:11:33,836 Is that what you're saying? 1906 01:11:33,836 --> 01:11:36,175 >> STUDENT: No, I'm just saying that-- so you're 1907 01:11:36,175 --> 01:11:38,354 printing rows first and then printing columns. 1908 01:11:38,354 --> 01:11:43,010 Can you also print columns first and then rows to get the same diagram? 1909 01:11:43,010 --> 01:11:44,760 SHARON: You could, but then you would have 1910 01:11:44,760 --> 01:11:47,370 to be careful of where you put the new line. 1911 01:11:47,370 --> 01:11:48,876 And how would you jump back? 1912 01:11:48,876 --> 01:11:55,082 1913 01:11:55,082 --> 01:11:56,790 JASON HIRSCHHORN: If you just switched it 1914 01:11:56,790 --> 01:12:01,190 and the values were different, instead of having four-- what is it? 1915 01:12:01,190 --> 01:12:02,530 Three by four. 1916 01:12:02,530 --> 01:12:08,955 I You would have four rows and three columns. 1917 01:12:08,955 --> 01:12:09,830 Does that make sense? 1918 01:12:09,830 --> 01:12:10,270 >> STUDENT: Yeah. 1919 01:12:10,270 --> 01:12:11,610 >> JASON HIRSCHHORN: So yeah, you could do that. 1920 01:12:11,610 --> 01:12:12,318 Yeah, definitely. 1921 01:12:12,318 --> 01:12:12,461 1922 01:12:12,461 --> 01:12:15,710 SHARON: But that would be literally just switching the names of the variables. 1923 01:12:15,710 --> 01:12:19,930 1924 01:12:19,930 --> 01:12:20,430 Good? 1925 01:12:20,430 --> 01:12:21,461 1926 01:12:21,461 --> 01:12:21,960 OK. 1927 01:12:21,960 --> 01:12:23,970 1928 01:12:23,970 --> 01:12:26,120 All right, P set one. 1929 01:12:26,120 --> 01:12:32,399 OK, so the first part of it you will be doing this, Mario. 1930 01:12:32,399 --> 01:12:32,940 Just kidding. 1931 01:12:32,940 --> 01:12:34,210 It's more like this. 1932 01:12:34,210 --> 01:12:39,350 And so when we just looked at the nested for loops, making that table, 1933 01:12:39,350 --> 01:12:45,960 think about how you might be able to print out these hashtags in this way. 1934 01:12:45,960 --> 01:12:50,090 And then right here how would you print this right here, this open space. 1935 01:12:50,090 --> 01:12:51,429 >> STUDENT: [INAUDIBLE]. 1936 01:12:51,429 --> 01:12:52,970 SHARON: Yeah, you just print a space. 1937 01:12:52,970 --> 01:12:54,720 OK, so just think about that. 1938 01:12:54,720 --> 01:12:56,699 1939 01:12:56,699 --> 01:12:58,740 HANNAH: And then the same part of the problem set 1940 01:12:58,740 --> 01:13:01,630 is a program called greedy.c, so that you're 1941 01:13:01,630 --> 01:13:03,810 going to want to think about conditionals 1942 01:13:03,810 --> 01:13:06,960 and making sure that you can make proper change. 1943 01:13:06,960 --> 01:13:10,780 And one little warning we have for you is be careful of floating point values. 1944 01:13:10,780 --> 01:13:14,530 If that means absolutely nothing to you, it'll be covered in lecture this week 1945 01:13:14,530 --> 01:13:16,410 and also in [INAUDIBLE] walk through, which 1946 01:13:16,410 --> 01:13:20,420 you guys will learn to love on the problem sets. 1947 01:13:20,420 --> 01:13:23,470 >> One thing that I really suggest, especially with Mario.c, 1948 01:13:23,470 --> 01:13:26,110 when you're doing the problem set, if you get stuck, 1949 01:13:26,110 --> 01:13:28,460 start by doing it on paper. 1950 01:13:28,460 --> 01:13:31,960 Write it out and actually sit there and pretend to be the computer, 1951 01:13:31,960 --> 01:13:36,530 and go through-- say I were the computer, 1952 01:13:36,530 --> 01:13:38,380 how would I follow this for loop through? 1953 01:13:38,380 --> 01:13:41,260 How would my variables in the for loop change? 1954 01:13:41,260 --> 01:13:43,640 So doing it on paper makes it 10 times easier 1955 01:13:43,640 --> 01:13:45,710 when you go to sit down at the computer. 1956 01:13:45,710 --> 01:13:46,840 So just my little plug. 1957 01:13:46,840 --> 01:13:50,060 >> SHARON: And also don't think that you have to code everything all at once. 1958 01:13:50,060 --> 01:13:53,060 Make sure you take an iterative process. 1959 01:13:53,060 --> 01:13:55,430 Do a little bit, print it out, see what happens. 1960 01:13:55,430 --> 01:13:57,044 1961 01:13:57,044 --> 01:13:58,710 Sometimes it's a little trial and error. 1962 01:13:58,710 --> 01:14:00,220 1963 01:14:00,220 --> 01:14:01,375 And come to office hours. 1964 01:14:01,375 --> 01:14:01,875 Super fun. 1965 01:14:01,875 --> 01:14:02,472 1966 01:14:02,472 --> 01:14:03,930 JASON HIRSCHHORN: So any questions? 1967 01:14:03,930 --> 01:14:05,186 1968 01:14:05,186 --> 01:14:07,317 All right guys, that was your first section. 1969 01:14:07,317 --> 01:14:08,400 HANNAH: Thanks for coming. 1970 01:14:08,400 --> 01:14:09,106 JASON HIRSCHHORN: Thanks for come. 1971 01:14:09,106 --> 01:14:09,890 SHARON: Thank you. 1972 01:14:09,890 --> 01:14:11,440 [APPLAUSE] 1973 01:14:11,440 --> 01:14:15,915