Hello and welcome to this lecture on do while loops do while loops are slightly identical to the while
loops.
The main difference between the two while loops on the wire loops is that the dual while loops will
evaluate the expression at the bottom of the loop while the while loop violates expression off the top.
So what that means is that with a do while loop you almost guarantee that the statement within the do
block are always executed at least once.
Right so this was the code block we used for a while loop illustration.
So I'm just gonna modify this code a little bit to illustrate the do while loop.
So here I'm gonna change this count here.
Will it change the count values to 4 and here instead of a while I'm just gonna type in a DO
AND I'M NOT GOING TO.
THERE'S NOT GONNA BE ANY
no conditions set there because it will evaluate the condition at the bottom here.
So this message will leave here.
So here's to mess.
This is a code that will execute if the expression I'm going to specify in the while loop in the while
condition is true so it will show are just changes values to execute something else
I just want a simple message so just typing
loop
executed
sucks X fully.
So this is a piece of code that will execute so it will display a message.
So this is where I now specify the condition.
So we a do loop.
It doesn't evaluate it doesn't check the condition until the end here.
So in that case this piece of code here would have executed at least once.
So inside here.
This is why I need to specify a while.
Because it's a do while loop.
So the expression no the condition is checked inside the wild part.
So I'll typing while and then I'll say count which is a variable is less than 0 equals 2 for
all right.
So if I run this code as long as this condition is met this piece of code will continue to execute.
So let me run that click Start and wait for the form to load.
So watch as I click on the form on the button says.
Loop executed successfully loop executed successfully.
So you keep saying that
our cat just jumped into the code.
I missed something because I want the way I've set it up at the moment.
The condition will always be true so I need to specify an increment.
So the way you do that is I'm just going to get rid of this bit here.
And time pain count
plus plus what this plus plus means is that it will increase the value of the count by one.
So eventually this condition will become force.
The way I had the codes set up previously before I run the code it will always be true.
In that case the loop will never end.
So behold now become an infinite loop because the condition will always be true.
Bye bye.
Put an account to account here.
I'm increasing.
This is a variable I'm saying that each time the loop is executed increase the value by 1.
So by increasing it each time you run it eventually it will exceed 4 and the condition would be force
which makes the code stop executing.
So let's start that again.
Click Start and click on the button that's 1
2 3 4.
I have had to change the value of the variable here to 1 because I had it set 2 4.
So what I meant was that the value or set to 4 and so the increment this counts here obviously did not
make any difference because once the value was 4 here each time you increase it.
It doesn't this condition will not be met.
So as he continues to loop.
So what I've done have changed the value to have changed the value of the variable called Count to 1.
So each time we click on the button the count will increase.
So you click on the button.
This will be executed so it will now be one instance.
You click on it again they'll be 2 3 4.
So once you've clicked on it four times then that count would have increased to 4 and the code will
stop executing.
So let's give that a go.
Sorry if I may have confused you with that.
So let's run that again click start.
Alright so watch out for this button.
I will once I click on it once.
The message should display and until I click the message four times we should include indicators account
or for the message will not disappear until the count is over.
So does the button click one.
So this is a first loop count that is a first count.
If I click okay there will be two click okay again they'll be three okay again.
Now before I click okay again it then should disappear.
All right.
So that's the count so once the exceeds for as long as the count is equal to all not greater than 4
it will continue to execute that code.
But once he exceed that count it called to stop running.
So as you can see it has stop running.
This message has stopped showing up so this is a message that will keep showing up as long as this condition
in the wild in the wild part of it is true.
So that is it for this lecture in this lecture.
We learnt about a do while loop so they say there's a difference between a while loop and a do while
loop with the do while loop.
The expression is evaluated at the end here while with a while loop it evaluates at the top.
So what they do while the code is bound to run at least once before it evaluates the condition in the
wild part of it.
Thank you for watching.
Bye for now.