WEBVTT 00:00:29.937 --> 00:00:37.377 Upon emerging from stasis, Ethic is the unfortunate recipient of three surprises. NOTE Paragraph 00:00:37.377 --> 00:00:40.339 The first: a prison cell. NOTE Paragraph 00:00:40.339 --> 00:00:43.504 The second: complete amnesia. NOTE Paragraph 00:00:43.504 --> 00:00:47.212 And the third: a mysterious stranger has gotten stuck 00:00:47.212 --> 00:00:50.867 squeezing through the bars on her window. NOTE Paragraph 00:00:50.867 --> 00:00:56.425 His name is Hedge, and he has come to help Ethic save the world. 00:00:56.425 --> 00:00:59.956 But first they have to break out of jail. NOTE Paragraph 00:00:59.956 --> 00:01:05.973 Hedge turns his hand into a lockpick and outlines the challenge ahead. NOTE Paragraph 00:01:05.973 --> 00:01:10.623 Each lock in the prison works in the same unusual way. 00:01:10.623 --> 00:01:17.251 Inside the keyhole is a red dial that can be rotated to one of 100 positions 00:01:17.251 --> 00:01:19.699 numbered 1 through 100. 00:01:19.699 --> 00:01:24.043 The key for a given cell spins the dial to the right position, 00:01:24.043 --> 00:01:28.913 which, when stopped there, makes it turn green and unlocks the door. 00:01:28.913 --> 00:01:33.628 It would be out of the question to steal keys from a guard, 00:01:33.628 --> 00:01:36.765 but Hedge has a better idea. NOTE Paragraph 00:01:36.765 --> 00:01:39.496 Hedge can carry out Ethic‘s commands. 00:01:39.496 --> 00:01:42.696 If Ethic tells him to walk 5 steps forward, 00:01:42.696 --> 00:01:46.171 turn right, then walk another 5 steps, 00:01:46.171 --> 00:01:49.723 that’s exactly what he’ll do. 00:01:49.723 --> 00:01:52.844 Hedge needs specific instructions though. 00:01:52.844 --> 00:01:57.000 If Ethic says “pick the lock” or “try every combination” 00:01:57.000 --> 00:02:03.685 that would be too vague, but “spin the dial 5 positions forward” would work. NOTE Paragraph 00:02:03.685 --> 00:02:07.707 Once out of the cell, they will only have a few moments to crack the lock 00:02:07.707 --> 00:02:12.225 for the outer prison door too before the guards catch them. 00:02:12.225 --> 00:02:17.705 So what instructions will allow Hedge to efficiently open any door? NOTE Paragraph 00:02:20.325 --> 00:02:24.395 Pause now to figure it out for yourself. NOTE Paragraph 00:02:25.775 --> 00:02:30.752 Before we explain the solution, here’s a hint. NOTE Paragraph 00:02:30.752 --> 00:02:37.180 A key programming concept that can help unlock the door is called a loop. 00:02:37.180 --> 00:02:42.510 This can be one or more instructions that Hedge will iterate— or repeat— 00:02:42.510 --> 00:02:46.654 a specified number of times, 00:02:46.654 --> 00:02:50.065 like “jump up and down 100 times.” 00:02:50.065 --> 00:02:55.245 Or an instruction that Hedge will repeat until a condition is met, 00:02:55.245 --> 00:03:00.231 such as “keep jumping up and down until it’s 7 o’clock.” NOTE Paragraph 00:03:00.231 --> 00:03:06.248 Pause now to figure it out for yourself. NOTE Paragraph 00:03:06.248 --> 00:03:10.136 The first thing that’s clear is that you need to find a way for Hedge 00:03:10.136 --> 00:03:14.230 to try every combination until one works. 00:03:14.230 --> 00:03:18.520 What takes a little more effort is how exactly you do so. NOTE Paragraph 00:03:18.520 --> 00:03:23.800 One solution would be to instruct Hedge to try every combination in succession. 00:03:23.800 --> 00:03:26.505 Try 1 and check the light. 00:03:26.505 --> 00:03:32.353 If it turns green, open the door, and if not, try 2. 00:03:32.353 --> 00:03:38.243 If that doesn’t work try 3. All the way up to 100. NOTE Paragraph 00:03:38.243 --> 00:03:41.817 But it would be tedious to lay that out in its entirety. 00:03:41.817 --> 00:03:44.253 Why write more than 100 lines of code, 00:03:44.253 --> 00:03:48.388 when you can do the same thing with just 3? NOTE Paragraph 00:03:48.388 --> 00:03:50.683 This is where a loop comes in. 00:03:50.683 --> 00:03:53.908 There are a few ways to go about this. 00:03:53.908 --> 00:03:56.263 The lock has 100 positions, 00:03:56.263 --> 00:04:02.314 so Ethic could say “Check the dial’s color, then spin the dial forward once, 00:04:02.314 --> 00:04:06.196 for 100 repetitions. 00:04:06.196 --> 00:04:13.012 Remember where the dial turns green, then have Hedge set it back to that number.” 00:04:13.012 --> 00:04:17.179 A loop like this, where you specify the number of times it repeats, 00:04:17.179 --> 00:04:20.165 is called a “for" loop. NOTE Paragraph 00:04:20.165 --> 00:04:22.107 But an even more efficient loop 00:04:22.107 --> 00:04:27.357 would have Hedge spin the dial one position at a time until it turns green 00:04:27.357 --> 00:04:31.844 and as soon as that happens, have him stop and open the door. 00:04:31.844 --> 00:04:35.253 That way if the door unlocks on 1, 00:04:35.253 --> 00:04:39.248 he doesn’t need to cycle through all the rest of the numbers. 00:04:39.248 --> 00:04:42.662 This is an “until” loop, 00:04:42.662 --> 00:04:47.442 because it involves doing an action until a condition is met. 00:04:47.442 --> 00:04:52.211 A similar, alternate approach would be to turn the dial while it’s still red, 00:04:52.211 --> 00:04:54.310 then stop. 00:04:54.310 --> 00:04:58.042 That’s called a “while” loop. NOTE Paragraph 00:04:58.042 --> 00:04:59.930 Back to the adventure. NOTE Paragraph 00:04:59.930 --> 00:05:07.030 Hedge loops through the combinations, and the cell opens at 41. 00:05:07.030 --> 00:05:10.951 Ethic and Hedge wait until the perfect moment in the guards’ rotation 00:05:10.951 --> 00:05:14.480 and make a break for it. NOTE Paragraph 00:05:14.480 --> 00:05:19.887 Soon, Ethic faces a choice: hide inside a mysterious crystal, 00:05:19.887 --> 00:05:23.851 or try to crack the outer door and make a run for it. 00:05:23.851 --> 00:05:26.117 Ethic chooses to run. 00:05:28.227 --> 00:05:34.643 The second door takes Hedge longer, requiring him to spin all the way to 93. 00:05:34.643 --> 00:05:37.193 But he gets it open 00:05:43.871 --> 00:05:48.741 and takes the opportunity to explain why he’s rescued Ethic. NOTE Paragraph 00:05:48.741 --> 00:05:50.469 The world is in turmoil: 00:05:50.469 --> 00:05:54.542 robots have taken over, and only Ethic can set things right. 00:05:54.542 --> 00:05:55.695 In order to do so, 00:05:55.695 --> 00:05:58.161 they’ll need to collect three powerful artifacts 00:05:58.161 --> 00:06:01.623 that are being used for nefarious purposes across the land. 00:06:01.623 --> 00:06:05.971 Only then can Ethic return to the world machine— that giant crystal— 00:06:05.971 --> 00:06:07.471 to set things right. NOTE Paragraph 00:06:19.685 --> 00:06:22.525 Ethic may have escaped the prison… 00:06:22.525 --> 00:06:25.455 but what has she gotten herself into?