1 00:00:00,210 --> 00:00:03,810 Before we start, did you try solving the workbook yourself? 2 00:00:03,840 --> 00:00:09,600 If not, please click the link in the resources folder and follow the instructions for this workbook. 3 00:00:10,830 --> 00:00:13,640 Welcome to Workbook 5.3. 4 00:00:13,650 --> 00:00:15,280 Let us get right into it. 5 00:00:15,300 --> 00:00:22,380 Task one is to ask to choose a number and we need to make sure Tammy can enter the value beside the 6 00:00:22,380 --> 00:00:23,190 question. 7 00:00:23,190 --> 00:00:27,630 I hope this made you think of print, not print line. 8 00:00:27,780 --> 00:00:35,070 If you missed the print versus print line article, I highly recommend you visit it before you look 9 00:00:35,070 --> 00:00:36,240 at this solution. 10 00:00:37,060 --> 00:00:39,560 So here we need to say Hi, Timmy. 11 00:00:39,580 --> 00:00:41,500 Choose a number to count to. 12 00:00:43,020 --> 00:00:44,280 Putting space. 13 00:00:44,950 --> 00:00:51,400 Then we'll say ent number is equal to skin dot next int. 14 00:00:52,670 --> 00:00:58,700 Because we use print instead of print line, it's not going to take up the entire line, which means 15 00:00:58,700 --> 00:01:04,569 next end is going to ask me to enter an integer right beside the following text. 16 00:01:04,580 --> 00:01:08,450 And now task two is to count from zero to that number. 17 00:01:08,450 --> 00:01:13,970 So that should have been a hint for you for I to start at zero. 18 00:01:14,730 --> 00:01:17,370 And it's to count to that number. 19 00:01:17,370 --> 00:01:25,080 So I hope you didn't say I is smaller than number, because if you do that, let's just say he enters 20 00:01:25,080 --> 00:01:26,910 the number five. 21 00:01:28,860 --> 00:01:34,310 By the time I reaches five, this is going to be false and the for loop will not run. 22 00:01:34,320 --> 00:01:40,860 So you want to make sure this is either I is smaller than or equal to number or I is smaller than number 23 00:01:40,860 --> 00:01:41,760 plus one. 24 00:01:42,270 --> 00:01:46,080 I don't know about you, but this seems like the more elegant approach. 25 00:01:46,260 --> 00:01:49,200 Then we'll say I plus plus. 26 00:01:51,360 --> 00:01:53,940 I hope you saw through my little trick there. 27 00:01:53,970 --> 00:01:57,960 And now we simply have to count from zero to the number that they choose. 28 00:01:57,990 --> 00:02:05,580 All we got to do is say print, not print line, because they all have to print on the same line. 29 00:02:06,470 --> 00:02:13,280 Every single time the loop runs, we will print the current number that we're iterating through, plus 30 00:02:13,280 --> 00:02:16,250 some space for the next number to print. 31 00:02:16,490 --> 00:02:17,150 All right. 32 00:02:17,150 --> 00:02:19,190 Let us now visualize the runtime. 33 00:02:21,890 --> 00:02:27,350 Before I let Timmy choose a number to count to let me put a breakpoint right over here. 34 00:02:27,530 --> 00:02:30,260 He is going to count up until five. 35 00:02:31,320 --> 00:02:31,620 All right. 36 00:02:31,620 --> 00:02:38,970 So number equals five I equals zero zero is smaller than or equal to five, which means this loop is 37 00:02:38,970 --> 00:02:40,080 going to run first. 38 00:02:40,080 --> 00:02:42,090 It's going to print the number zero. 39 00:02:44,100 --> 00:02:49,860 And what's beautiful about print as opposed to print line is that print prints, text, but it does 40 00:02:49,860 --> 00:02:51,390 not move to a new line. 41 00:02:51,390 --> 00:02:58,410 So the second time we run this loop, this time I equaling one one is going to print on the exact same 42 00:02:58,410 --> 00:02:59,040 line. 43 00:02:59,520 --> 00:03:00,900 Now I equals two. 44 00:03:02,890 --> 00:03:04,990 Three four. 45 00:03:06,180 --> 00:03:06,960 Five. 46 00:03:07,110 --> 00:03:12,120 And by the time we go back, I a plus plus is going to increase I to equal six. 47 00:03:12,120 --> 00:03:17,130 Six is not smaller than or equal to five, which means the loop is going to break. 48 00:03:17,130 --> 00:03:23,610 And we were able to accomplish our task, which was to count from zero to whatever number Tammy chooses.