1 00:00:01,160 --> 00:00:02,600 Conditional loops. 2 00:00:02,630 --> 00:00:09,320 In the previous section we gave a controversial example where the condition in the for loop pulled from 3 00:00:09,320 --> 00:00:10,040 the data. 4 00:00:10,730 --> 00:00:14,810 In this example there is a no live variable used in this condition. 5 00:00:14,810 --> 00:00:18,100 This is then candidate for the wild conditional loop here. 6 00:00:18,110 --> 00:00:20,360 So while here. 7 00:00:21,250 --> 00:00:22,910 Okay, let's make it like that. 8 00:00:22,910 --> 00:00:24,020 My data. 9 00:00:24,770 --> 00:00:28,520 Pull my data and make it true. 10 00:00:29,300 --> 00:00:44,600 Here and while my data here then integer e here my data or we can make it into years bull E here my 11 00:00:44,600 --> 00:00:46,910 data and STD. 12 00:00:48,810 --> 00:00:56,370 S, t d or c out uh, e here and and line here. 13 00:00:59,890 --> 00:01:04,270 As you can see, it created and printed a bunch of ones here. 14 00:01:04,270 --> 00:01:06,040 So this means true here. 15 00:01:06,100 --> 00:01:12,910 The statement will continue to loop until the expiration has a value of false here. 16 00:01:13,090 --> 00:01:21,400 So as with four, you can exit the while loop with prick return true or go to keywords and you can indicate 17 00:01:21,400 --> 00:01:25,860 that the next loop should be executed using the continue statement. 18 00:01:25,870 --> 00:01:32,690 So the first time the var statement is called the condition test before the loop is executed. 19 00:01:32,710 --> 00:01:40,540 In some cases you may want to you may want a loop as good at least once and then test the condition 20 00:01:40,540 --> 00:01:46,810 so much like it depended upon the action in the loop to see if the loop should be repeated. 21 00:01:46,990 --> 00:01:50,910 The way to do this is to use the while loop here. 22 00:01:50,920 --> 00:01:54,460 So now let's make it my data. 23 00:01:54,460 --> 00:01:55,120 False. 24 00:01:56,390 --> 00:01:57,140 Pulse. 25 00:01:58,520 --> 00:02:00,370 As you can see, we printed nothing. 26 00:02:00,370 --> 00:02:08,530 But if we do the do while loop, for example, do do here. 27 00:02:10,440 --> 00:02:11,800 Uh, okay. 28 00:02:11,820 --> 00:02:16,770 Is C out E here or my data here? 29 00:02:19,820 --> 00:02:20,850 And learn. 30 00:02:21,860 --> 00:02:22,670 And. 31 00:02:24,710 --> 00:02:29,690 We're going to add while here while my data. 32 00:02:30,820 --> 00:02:32,460 Here, as you can see here. 33 00:02:32,470 --> 00:02:33,760 So let's print it out. 34 00:02:34,210 --> 00:02:43,210 As you can see here, it printed zero because the vita du while loop, the du conditioning du court 35 00:02:43,210 --> 00:02:46,810 here has to be executed at least once. 36 00:02:46,810 --> 00:02:48,130 So this executes. 37 00:02:48,130 --> 00:02:56,530 And when when our code tries to find that if my data is true or false, it returns the false. 38 00:02:56,530 --> 00:02:59,020 And that's why it printed only once here. 39 00:02:59,020 --> 00:03:01,870 But in this case it printed no, nothing here. 40 00:03:02,830 --> 00:03:09,220 So the, uh, here semicolon after this is required here, this is the class. 41 00:03:09,730 --> 00:03:17,560 So, uh, as you can see here, this loop printed, uh, once here, false. 42 00:03:17,590 --> 00:03:20,350 Uh, despite of my data having false here. 43 00:03:20,620 --> 00:03:26,920 So the difference between two types of loop is that the condition here, the condition is tested before 44 00:03:26,920 --> 00:03:29,200 the loop is executed in the while loop. 45 00:03:29,200 --> 00:03:33,760 And so the loop may not be executed in a DU while loop. 46 00:03:33,760 --> 00:03:42,520 Here the condition is called after the loop, which means that with a do while loop, the loop statements 47 00:03:42,520 --> 00:03:46,060 are always called at once.