1 00:00:01,030 --> 00:00:02,480 Conditional loops. 2 00:00:02,500 --> 00:00:09,040 In the previous section, we gave a controversial example where the condition in the for loop pulled 3 00:00:09,040 --> 00:00:09,910 from the data. 4 00:00:10,510 --> 00:00:14,710 In this example, there is a null variable used in this condition. 5 00:00:14,710 --> 00:00:18,030 This is a candidate for the while conditional loop here. 6 00:00:18,040 --> 00:00:20,350 So while here. 7 00:00:21,190 --> 00:00:22,870 Okay, let's make it like that. 8 00:00:22,870 --> 00:00:28,450 My data bull my data and make it true. 9 00:00:29,260 --> 00:00:40,960 Here and while my data here then integer here my data or we can make it into here. 10 00:00:41,470 --> 00:00:46,480 Okay bull here my data and STD. 11 00:00:48,920 --> 00:00:56,450 STD or C out E here and N line here. 12 00:00:59,820 --> 00:01:04,230 As you can see, it created and printed a bunch of ones here. 13 00:01:04,230 --> 00:01:05,910 So this means true here. 14 00:01:05,940 --> 00:01:12,920 This statement will continue to loop until the expression, um, has a value of false here. 15 00:01:12,930 --> 00:01:21,330 So as with four you can exit the while loop with brick return true or go to keywords and you can indicate 16 00:01:21,330 --> 00:01:25,800 the next loop should be executed using the continue statement. 17 00:01:25,800 --> 00:01:32,610 So the first time the while statement is called the condition tested before the loop is executed. 18 00:01:32,610 --> 00:01:40,470 In some cases you may want to you may want the loop as good at least once and then test the condition. 19 00:01:40,470 --> 00:01:46,800 So most likely depended upon the action in the loop to see if the loop should be repeated. 20 00:01:46,830 --> 00:01:50,880 The way to do this is to use do while loop here. 21 00:01:50,880 --> 00:01:55,050 So now let's make it my data false. 22 00:01:56,380 --> 00:01:56,920 Pulse. 23 00:01:58,170 --> 00:01:58,470 Here. 24 00:01:58,470 --> 00:02:00,290 As you can see, we printed nothing. 25 00:02:00,300 --> 00:02:08,490 But if we do the do while loop for example, do do here. 26 00:02:10,430 --> 00:02:11,140 Uh. 27 00:02:11,150 --> 00:02:11,800 Okay. 28 00:02:11,810 --> 00:02:16,730 Is she out e here or my data here? 29 00:02:19,660 --> 00:02:20,680 And line. 30 00:02:21,820 --> 00:02:22,630 And. 31 00:02:24,610 --> 00:02:29,620 We're going to add the file here while my data. 32 00:02:30,750 --> 00:02:32,490 Here, as you can see here. 33 00:02:32,490 --> 00:02:33,720 So let's print it out. 34 00:02:33,930 --> 00:02:43,140 As you can see here, it printed zero because the with the do while loop the do condition here do code 35 00:02:43,140 --> 00:02:46,740 here has to be executed at least once. 36 00:02:46,740 --> 00:02:56,100 So this executes and when when our code tries to find out if my data is true or false, it returns the 37 00:02:56,100 --> 00:02:56,430 false. 38 00:02:56,430 --> 00:02:58,950 And that's why it printed only once here. 39 00:02:58,950 --> 00:03:01,920 But in this case, it printed no nothing here. 40 00:03:02,610 --> 00:03:09,240 So the, uh, here semicolon after this is required here, this is a class. 41 00:03:09,570 --> 00:03:19,470 So, uh, as you can see here, this loop printed, uh, once here, false, despite of my data having 42 00:03:19,500 --> 00:03:20,400 false here. 43 00:03:20,400 --> 00:03:26,820 So the difference between two types of loop is that the condition here, the condition is tested before 44 00:03:26,820 --> 00:03:29,100 the loop is executed in the while loop. 45 00:03:29,100 --> 00:03:33,760 And so the loop may not be executed in a do 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,150 are always called at once.