1 00:00:00,000 --> 00:00:00,260 2 00:00:00,260 --> 00:00:02,830 >> SPEAKER 1: It turns out there's still an opportunity to improve this 3 00:00:02,830 --> 00:00:04,240 program's design. 4 00:00:04,240 --> 00:00:08,860 Notice in my for loop that on each iteration, I'm checking that i is less 5 00:00:08,860 --> 00:00:10,520 than the string length of s. 6 00:00:10,520 --> 00:00:13,920 But the string length of s is always going to be the same, because s itself 7 00:00:13,920 --> 00:00:15,010 is not changing. 8 00:00:15,010 --> 00:00:18,630 And yet, every time through this loop I'm checking the string length of s, 9 00:00:18,630 --> 00:00:21,810 the string length of s, the string length of s, which is just silly. 10 00:00:21,810 --> 00:00:24,580 Because surely it must take some amount of time to figure out a 11 00:00:24,580 --> 00:00:25,450 string's length. 12 00:00:25,450 --> 00:00:28,680 And I'm wasting that time by asking the same question again and again. 13 00:00:28,680 --> 00:00:32,920 >> Well, it turns out we can improve this by declaring, say, a second variable 14 00:00:32,920 --> 00:00:34,470 inside of my for loop. 15 00:00:34,470 --> 00:00:38,240 Let's call it n-- and separate it from i, with a comma like this-- 16 00:00:38,240 --> 00:00:42,000 and set n equal to the string length of s. 17 00:00:42,000 --> 00:00:42,990 Semicolon. 18 00:00:42,990 --> 00:00:46,350 And now, let's change my condition to not compare i against the string 19 00:00:46,350 --> 00:00:49,560 length of s per se, but instead against n. 20 00:00:49,560 --> 00:00:52,360 In this way, we initialize n to the string length of s. 21 00:00:52,360 --> 00:00:57,210 But on each iteration of my loop, I'll instead be checking i against n. 22 00:00:57,210 --> 00:00:59,628