1 00:00:00,000 --> 00:00:00,430 2 00:00:00,430 --> 00:00:02,540 >> DAVID J. MALAN: Let's refine our printing of ASCII characters just a 3 00:00:02,540 --> 00:00:03,380 little bit. 4 00:00:03,380 --> 00:00:07,490 Because characters are simply numbers underneath the hood, it turns out that 5 00:00:07,490 --> 00:00:11,220 even within our looping construct we can actually iterate not only over 6 00:00:11,220 --> 00:00:14,360 just ints, but also over the chars themselves. 7 00:00:14,360 --> 00:00:18,290 >> In other words, I could tell the computer to start iterating from A up 8 00:00:18,290 --> 00:00:22,400 through Z rather than even have to know more or deal with the equivalence 9 00:00:22,400 --> 00:00:25,960 of A being 65 and Z being 90. 10 00:00:25,960 --> 00:00:29,650 In other words, I can reimplement this program as follows. 11 00:00:29,650 --> 00:00:33,190 >> For char, let's call it c, equals. 12 00:00:33,190 --> 00:00:36,520 And now I'd like to start iterating when the character equals quote, 13 00:00:36,520 --> 00:00:38,620 unquote, A. And notice the single quotes. 14 00:00:38,620 --> 00:00:43,250 This is indeed a single character and not a one character string. 15 00:00:43,250 --> 00:00:44,240 >> Semicolon. 16 00:00:44,240 --> 00:00:48,850 Let's iterate so long as c is less than or equal to capital Z, also 17 00:00:48,850 --> 00:00:49,720 single quoted. 18 00:00:49,720 --> 00:00:53,290 And on each iteration of this loop, let's increment c itself. 19 00:00:53,290 --> 00:00:55,880 Because again, at the end of the day, c is just a number 20 00:00:55,880 --> 00:00:56,700 underneath the hood. 21 00:00:56,700 --> 00:00:59,470 And so we can also manipulate it as such. 22 00:00:59,470 --> 00:01:05,540 >> Now inside this loop, let's print out that percent i is percent 23 00:01:05,540 --> 00:01:07,460 c, backslash n. 24 00:01:07,460 --> 00:01:13,900 And plug in now for i the result of casting c, a char, to an int, followed 25 00:01:13,900 --> 00:01:16,400 by c itself. 26 00:01:16,400 --> 00:01:17,260 >> Semicolon. 27 00:01:17,260 --> 00:01:18,210 Save my file. 28 00:01:18,210 --> 00:01:20,280 And let's compile and run. 29 00:01:20,280 --> 00:01:25,790 Make ASCII 1 dot slash ASCII 1. 30 00:01:25,790 --> 00:01:32,740 And, scrolling back up, we see that 65 is again A, 66 is again B, and all the 31 00:01:32,740 --> 00:01:36,110 way down to 90 is again Z. 32 00:01:36,110 --> 00:01:37,383