1
00:00:00,690 --> 00:00:01,410
Welcome back.

2
00:00:01,589 --> 00:00:08,640
And this video we are going to look at do while loops and while loops are very similar to the wire loops

3
00:00:08,880 --> 00:00:17,280
and they just differ in a small detail or small difference, which means that they don't check before

4
00:00:17,520 --> 00:00:19,330
they execute at least once.

5
00:00:19,530 --> 00:00:21,060
So what does that even mean?

6
00:00:21,450 --> 00:00:22,810
Well, let's have a look at this.

7
00:00:23,130 --> 00:00:27,840
Let's say we have this variable again, this variable X and.

8
00:00:28,750 --> 00:00:34,930
Let's say we start at 1:00 and then we do the following, so we do.

9
00:00:36,440 --> 00:00:44,360
And we only do a while, but we do this once, all right, so I'm just going to write down the syntax

10
00:00:44,840 --> 00:00:46,290
before we do anything else.

11
00:00:46,310 --> 00:00:49,130
So I'm going to use this ax again.

12
00:00:49,310 --> 00:00:51,310
Actually, let me set that to one here.

13
00:00:51,890 --> 00:00:53,380
It was 100 here.

14
00:00:54,410 --> 00:00:55,610
So let's leave it like this.

15
00:00:55,880 --> 00:00:56,210
All right.

16
00:00:56,220 --> 00:01:02,450
So we have this variable X and then we have this Dukey word, curly brackets, and then we have this

17
00:01:02,450 --> 00:01:05,010
wild keyword in those curly brackets.

18
00:01:05,030 --> 00:01:10,970
It's important that we get to a situation where this wild statement is not true at one point anymore

19
00:01:11,810 --> 00:01:15,330
and it's done by incrementing X in our case.

20
00:01:15,800 --> 00:01:21,050
So in this case, the do while loop will be run 10 times and will go from one to 10.

21
00:01:21,800 --> 00:01:23,430
So let's print something here.

22
00:01:23,600 --> 00:01:35,180
I'm just going to print X here, so nothing too fancy again, and I'm just going to say print do while

23
00:01:35,180 --> 00:01:38,870
loop is done so that we are it says de Waal, who has done this.

24
00:01:39,080 --> 00:01:43,820
Scroll up one, two, three, four, five and so forth, and then two while loop is done.

25
00:01:44,090 --> 00:01:47,330
So how is that different to the wire loop?

26
00:01:48,020 --> 00:01:54,110
Well, the difference is that let's say our X is not one, but it's 15.

27
00:01:54,920 --> 00:01:59,150
Then this condition is not true because 15 is not less or equal.

28
00:01:59,150 --> 00:02:00,800
10, it's higher than 10.

29
00:02:01,550 --> 00:02:04,190
But the court will still be executed at least once.

30
00:02:04,350 --> 00:02:08,030
Let's just see what that really means and how that looks like.

31
00:02:09,199 --> 00:02:10,139
And there we are.

32
00:02:10,490 --> 00:02:18,230
It says 15 and while it was done so it printed 15, but it didn't do the rest of the iteration, so

33
00:02:18,230 --> 00:02:21,530
it didn't run 10 times or however many times.

34
00:02:21,830 --> 00:02:27,230
It really just ran once because the condition is not met, but still it ran once.

35
00:02:27,230 --> 00:02:29,790
And that's something that is really important sometimes.

36
00:02:30,110 --> 00:02:31,820
So when would you use a do?

37
00:02:31,820 --> 00:02:33,170
While instead of a while?

38
00:02:33,500 --> 00:02:41,300
Well, there are multiple applications, but let's say you want to run an execution on multiple users

39
00:02:41,300 --> 00:02:45,750
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,830 --> 00:02:59,590
You want to print the names of that list or you want to work through that list.

43
00:03:00,170 --> 00:03:05,000
And that's something that you would do first and then you could check, OK, is the connection established?

44
00:03:05,210 --> 00:03:09,290
And if it's established, then run through the list or do the execution.

45
00:03:09,830 --> 00:03:14,570
Of course, there are multiple more applications for this, but we will see throughout the course when

46
00:03:14,570 --> 00:03:16,040
it makes sense to use to while.

47
00:03:16,310 --> 00:03:22,820
So I'd say let's just check out for loops in the next video to see the third type of loop, which is

48
00:03:22,820 --> 00:03:24,680
very similar to a wire loop.

49
00:03:25,010 --> 00:03:25,700
So see their.

