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