Welcome back.
And this video we're going to look at do while loops and while loops are very similar to the wild loops
and they just differ in a small detail or small difference, which means that they don't check before
they execute at least once.
So what does that even mean?
Well, let's have a look at this.
Let's say we have this variable again, this variable X and.
Let's say we start at one and then we do the following, so we do.
And we only do while, but we do this once.
All right, so I'm just going to write down the syntax before we do anything else.
So I'm going to use this X again.
Actually, let me set that to one here.
It was 100 here.
So let's leave it like this.
All right.
So we have this variable X and then we have this do keyword curly brackets and then we have this while
keyword in those curly brackets.
It's important that we get to a situation where this whale statement is not true at one point anymore,
and it's done by incrementing X in our case.
So in this case, this do.
While loop will be run 10 times, it will go from one to 10.
So let's print something here.
I'm just going to print X here.
So nothing too fancy again.
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.
This scroll up one two, three four, five and so forth and then to two by loop is done.
So how is that different to the while loop?
Well, the difference is that let's say our X is not one, but it's 15.
Then this condition is not true because 15 is not less or equal.
Ten, it's higher than 10.
But the court will still be executed at least once.
Let's just see what that really means and how that looks like.
And there we are.
Just 15 and while it was done so, it printed 15, but it didn't do the rest of the iteration, so it
didn't run 10 times or however many times and really just ran once because the condition is not met.
But still, it ran once, and that's something that is really important sometimes.
So when would you use a do while instead of a while?
Well, there are multiple applications, but let's say you want to run an execution on multiple users
of a list, but you need to get that list from a server.
So what you would do is you would try to establish the connection to the server and only as long as
the connection to the server works.
You want to print the names of that list or you want to work through that list.
And that's something that you would do first and then you could check, OK, is the connection established
and if it's established, then run through the list or do the execution.
Of course, there are multiple more applications for this, but we will see throughout the course when
it makes sense to use do well.
So I'd say, let's just check out for loops in the next video to see the third type of loop, which
is very similar to a wire loop.
So see you there.