1 00:00:00,660 --> 00:00:01,410 Welcome back. 2 00:00:01,589 --> 00:00:08,580 And this video we're going to look at do while loops and while loops are very similar to the wild loops 3 00:00:08,910 --> 00:00:17,250 and they just differ in a small detail or small difference, which means that they don't check before 4 00:00:17,550 --> 00:00:19,290 they execute at least once. 5 00:00:19,560 --> 00:00:21,030 So what does that even mean? 6 00:00:21,450 --> 00:00:22,740 Well, let's have a look at this. 7 00:00:23,160 --> 00:00:27,810 Let's say we have this variable again, this variable X and. 8 00:00:28,810 --> 00:00:34,900 Let's say we start at one and then we do the following, so we do. 9 00:00:36,470 --> 00:00:40,880 And we only do while, but we do this once. 10 00:00:41,930 --> 00:00:46,190 All right, so I'm just going to write down the syntax before we do anything else. 11 00:00:46,340 --> 00:00:49,100 So I'm going to use this X again. 12 00:00:49,340 --> 00:00:51,290 Actually, let me set that to one here. 13 00:00:51,920 --> 00:00:53,360 It was 100 here. 14 00:00:54,410 --> 00:00:55,580 So let's leave it like this. 15 00:00:55,910 --> 00:00:56,180 All right. 16 00:00:56,180 --> 00:01:02,750 So we have this variable X and then we have this do keyword curly brackets and then we have this while 17 00:01:02,750 --> 00:01:04,980 keyword in those curly brackets. 18 00:01:05,000 --> 00:01:10,940 It's important that we get to a situation where this whale statement is not true at one point anymore, 19 00:01:11,840 --> 00:01:15,320 and it's done by incrementing X in our case. 20 00:01:15,830 --> 00:01:17,030 So in this case, this do. 21 00:01:17,030 --> 00:01:21,020 While loop will be run 10 times, it will go from one to 10. 22 00:01:21,830 --> 00:01:23,390 So let's print something here. 23 00:01:23,630 --> 00:01:27,350 I'm just going to print X here. 24 00:01:28,340 --> 00:01:30,200 So nothing too fancy again. 25 00:01:30,800 --> 00:01:38,570 And I'm just going to say print do while loop is done so that we are, it's as do while Loop is done. 26 00:01:38,570 --> 00:01:43,790 This scroll up one two, three four, five and so forth and then to two by loop is done. 27 00:01:44,120 --> 00:01:47,300 So how is that different to the while loop? 28 00:01:47,990 --> 00:01:54,080 Well, the difference is that let's say our X is not one, but it's 15. 29 00:01:54,920 --> 00:01:59,120 Then this condition is not true because 15 is not less or equal. 30 00:01:59,120 --> 00:02:00,770 Ten, it's higher than 10. 31 00:02:01,520 --> 00:02:04,130 But the court will still be executed at least once. 32 00:02:04,400 --> 00:02:08,000 Let's just see what that really means and how that looks like. 33 00:02:09,199 --> 00:02:10,130 And there we are. 34 00:02:10,600 --> 00:02:18,290 Just 15 and while it was done so, it printed 15, but it didn't do the rest of the iteration, so it 35 00:02:18,290 --> 00:02:24,890 didn't run 10 times or however many times and really just ran once because the condition is not met. 36 00:02:25,640 --> 00:02:29,780 But still, it ran once, and that's something that is really important sometimes. 37 00:02:30,140 --> 00:02:33,140 So when would you use a do while instead of a while? 38 00:02:33,500 --> 00:02:41,270 Well, there are multiple applications, but let's say you want to run an execution on multiple users 39 00:02:41,270 --> 00:02:45,740 of a list, but you need to get that list from a server. 40 00:02:46,100 --> 00:02:53,060 So what you would do is you would try to establish the connection to the server and only as long as 41 00:02:53,060 --> 00:02:54,530 the connection to the server works. 42 00:02:54,800 --> 00:02:59,540 You want to print the names of that list or you want to work through that list. 43 00:03:00,200 --> 00:03:04,970 And that's something that you would do first and then you could check, OK, is the connection established 44 00:03:05,240 --> 00:03:09,260 and if it's established, then run through the list or do the execution. 45 00:03:09,830 --> 00:03:14,540 Of course, there are multiple more applications for this, but we will see throughout the course when 46 00:03:14,540 --> 00:03:16,010 it makes sense to use do well. 47 00:03:16,310 --> 00:03:22,670 So I'd say, let's just check out for loops in the next video to see the third type of loop, which 48 00:03:22,670 --> 00:03:24,620 is very similar to a wire loop. 49 00:03:25,040 --> 00:03:25,670 So see you there.