No less experimented with the while loop.
So the next example is example five and let's say we want to print zero through four using a while loop.
I'll just copy the header we have here and bring it here and see this is.
Example number five.
This should have been four.
Sorry.
I can see this example number five here
and this time they say we want to print 0 through 4 like this.
Melissa will come here and then we have ever had.
No no no no.
Coursera.
We don't need a semicolon.
And then we can see
for gnome is less than five semicolon.
Now call on here and then print num
then we can come down further and say num plus 1 like this.
So it's going to print this and then add one to num iterate.
This is the iterator this time just like in any other programming language.
So let's see what happens.
Let's see what example 5 prints click over here and then click here to run the module click here.
Okay.
And as you can see we have 0 1 2 3 4 and this is how we get there.
Now let's explore the use of the break key word we can use break to break out of the loop and there's
another word continue which we can use to jump over certain steps in the loop is different from this
though.
Let's see what I mean.
We have example six I just copy and paste this down here and it changed this number five to six and
a simple six.
Right.
So then let's see.
Let's just come up with an example.
Let's say we have a variable count because you say this count of course zero and then we can say wow
true.
So crews have defined word.
We can just use while true here and it's the same eyes while 1 while a true print count the statement
is false cos count because zero zero means force.
So we can say print count while true print count and then over here we can see count plus 1.
This is what we may count true
count plus of course one or count of course count plus one.
And we can see if the count is greater than five.
Greater than or equal to 5.
Yes also fine we can say greater than or equal to 5 meaning if count the value count becomes five then
break.
We got a call on her.
Her colon and then we can just put a break here.
So then this is going to count zero through five right.
So let's see what I mean.
Click over here to run.
Click here to save.
Because I didn't save.
We misspelled.
Can't remember her.
Can't I use that we'll see here.
Sorry about that.
Click here to run it.
OK now she can see an example of success 0 1 2 3 4.
So when you got here while conscious greeted on equal to five it escaped us and it's great.
It would have returned here to print but we used a break statement no less have a much more creative
example less design the script to skip over even numbers so I can come down here and you'll see examples
seven.
Let's cover this example seven and can print here we can give it a title for your revision.
Here this is Kip event.
Numbers like this and we can come in and see a print example seven resorts can come and start with a
for loop we can see four for X and use the range range of 10 minutes zero through nine and then over
here we can have an if condition if X percentage to of course because you.
This is how we would detect an even number if this the case continue.
And then once that is done we can see a print x like this
then we can just click here to save and then run.
We go in.
We just set for X range.
It's very minor.
Okay.
Let's click here to run then okay you can see it's printed just the numbers 1 3 5 7 9.
Right.
So this is a we've had a lot of you know play time with the loops.
I think this is enough examples.
We've treated every use case off the wall and the for loop you have any questions just send me a message
or if you need more explanation just send me a message or leave in the questions area.
So this order is and have a good day I shall see you in the next lesson.