1 00:00:00,500 --> 00:00:01,340 Welcome back. 2 00:00:01,730 --> 00:00:08,660 Before we go to the follow-up, I wanted to show you another application of the while loop because it 3 00:00:08,660 --> 00:00:12,800 will make it a little more clear what the differences and when to use what. 4 00:00:13,160 --> 00:00:19,940 So, for example, the for loop is really there to iterate through ranges, arrays and so forth, and 5 00:00:19,940 --> 00:00:22,550 we will see what that means in the next video. 6 00:00:22,880 --> 00:00:30,020 But before we do so, we will have to look at while loops which are great to execute a block of called 7 00:00:30,020 --> 00:00:33,320 repeatedly as long as the condition is met, as we saw earlier. 8 00:00:33,830 --> 00:00:39,170 So let's have an example where we don't look at numbers because so far we only looked at numbers. 9 00:00:39,440 --> 00:00:41,500 We said, OK, var x. 10 00:00:41,510 --> 00:00:44,300 As long as this white, then do something. 11 00:00:44,700 --> 00:00:52,720 But now let's say we have the situation where we have a variable called felt temperature and that one 12 00:00:52,730 --> 00:00:53,480 will be called. 13 00:00:53,480 --> 00:00:56,180 So let's say we are in the room and it feels like it's cold. 14 00:00:56,930 --> 00:01:03,200 So we don't know directly what temperature it is in terms of degrees, right, in terms of degrees Celsius. 15 00:01:03,710 --> 00:01:09,860 So we have also a value called room temperature, which actually is that value. 16 00:01:09,870 --> 00:01:11,420 So let's say 10 degrees. 17 00:01:12,620 --> 00:01:13,100 And. 18 00:01:14,230 --> 00:01:21,310 Now we will run a wild loop, which will increase the temperature, the room temperature by one degree 19 00:01:21,880 --> 00:01:27,370 until it's warm enough, so that felt temperature is not cold anymore. 20 00:01:28,210 --> 00:01:36,610 So here we are, just going to say as long as felts temp is cold, please run this wire loop, which 21 00:01:36,610 --> 00:01:39,490 will, as I said, increase the room temperature. 22 00:01:42,570 --> 00:01:48,390 So now, of course, we still need a situation where this condition is not met anymore, so we need 23 00:01:48,390 --> 00:01:56,940 to create this situation so we can check if the room temperature is greater or equal. 24 00:01:57,180 --> 00:01:57,780 20. 25 00:01:59,220 --> 00:02:07,320 Then set a felt temperature, too comfy, so too comfortable, so it's not going to be cold anymore. 26 00:02:07,800 --> 00:02:11,280 And also print something onto the console, parental and. 27 00:02:12,450 --> 00:02:15,000 It's comfy now. 28 00:02:15,570 --> 00:02:17,430 So now if we execute this. 29 00:02:19,160 --> 00:02:21,170 It will just print its comfy now. 30 00:02:22,040 --> 00:02:24,020 Why is that what happened in this whole thing? 31 00:02:24,350 --> 00:02:30,710 Well, we set the felt temperature too cold because when it's 10 degrees Celsius, then it's pretty 32 00:02:30,710 --> 00:02:33,890 cold and you don't want to be in the room when it's that cold. 33 00:02:34,080 --> 00:02:35,990 You want it to be 20 degrees Celsius. 34 00:02:37,530 --> 00:02:40,110 Which is sixty eight degrees Fahrenheit. 35 00:02:40,800 --> 00:02:47,520 All right, so what you say is as long as it's called, please turn up the heat, so increase the room 36 00:02:47,520 --> 00:02:48,540 temperature by one. 37 00:02:49,520 --> 00:02:54,050 And as soon as the room temperature hits 20 degrees. 38 00:02:55,470 --> 00:02:58,980 Then set the false temperature too comfy. 39 00:02:59,070 --> 00:03:02,670 So now in the room, we feel like all right is comfy, it's a good temperature. 40 00:03:03,120 --> 00:03:08,760 We can maybe even get rid of our jacket and then we can print. 41 00:03:09,060 --> 00:03:09,840 It's comfy now. 42 00:03:10,760 --> 00:03:16,550 And our while loop will stop, so at that point, our while loop will not increase the room temperature 43 00:03:16,550 --> 00:03:22,430 anymore and it will jump out of this whole loop and execute whatever comes afterwards. 44 00:03:24,030 --> 00:03:29,250 So this is just another application where you see that it doesn't have to be an integer that we're checking 45 00:03:29,250 --> 00:03:29,580 here. 46 00:03:29,820 --> 00:03:33,750 It can be whatever condition that has to be met. 47 00:03:34,080 --> 00:03:39,960 And as soon as this condition is not only met anymore, the while loop will stop executing its block 48 00:03:39,960 --> 00:03:41,850 here, its body, it's called block.