Biton while loop.
So the while loop syntax in Python that while looping python is used to iterate over a block of code,
as long as the test expression that that is a condition is true, when the condition is well, then
it will come out from the white block.
So we generally use the loop when we don't know the beforehand and the number of times to iterate.
So whenever we know that how many times we are going to iterate, we are having the form.
But if you don't know that, how many times we're going to iterate, then we shall go for this while
looping.
Because when the condition is through, the loop will get executed.
When the condition is false, then it will come out of the loop construct.
So here is the respective body.
There's a while test and don't forget to get this on there and then body of white.
So there is one indentation is there that will indicate that this these are the statements which will
be under this while so intertwined.
Look, the content will come this expression.
If the expression is true, then the body of oil will get executed again.
The test expression will be tested.
And if the expression is false, then it will exit from the loop.
So in this way, the respective python while loop will get executed.
While loop with LTH syntax in Python, so let's think about that for the fort, we can have an optional
S block with the while loop as well.
The A's part is executed in the condition.
In the while Loop evaluates to false when the connection will become false, then the start getting
executed.
When the condition is true, then the body will go on keeping their execution so the Y loop can be terminated
with the break.
A statement in such cases of ill spot is ignored.
If there is some Bryk statement, Danneels part will get ignored.
Hennesey while loops and spot runs if no break occurs and the condition is false.
So whenever there is no public statement, whenever the condition is false, then only the part will
get its control to execute its its respective code written under the else block.
So let us go for one practical demonstration for the is the understanding of this while loop in python
coding in this demonstration we are discussing the use of while loop in our python coding so that we
have made Aisgill two three has been initialized with three while I is greater than Gittel Colon.
So whenever you are giving colon then the next line will be coming with the indentation that wins.
This line is within the while block printing the value of PI and also decreasing the value of PI by
one hit.
So let us go for the execution.
You can find that three to one they are getting printed because when the value up I will become one.
So one is that the condition is true.
So print one is getting printed now.
One is getting decreased by one, so it will become zero.
So I will have the zero zero zero zero.
The condition is false.
So that is why it is coming out from the Y look.
So let us go for a while else structure.
So while I less than 10 print I and then I blast equal to one.
That means when the value of I is not equal to ten below ten, that means when the eye is less than
ten then the I will get printed and each and every time that I will be increased by one here and when
this loop will get terminated then you are going to print that displayed successfully.
So let us go for the execution.
Say it for some just initializing decide with the values of five here.
So now see the five is getting printed so five has got increased to six, six is less than ten, so
six has got printed.
Similarly seven, eight and nine has got printed.
Nine has been increased by one.
So it has become ten.
So ten less than ten.
The condition is also will be coming to the L spot and displayed successfully.
The message is getting printed here.
So in this we can find that how this respective while with LS structure is there, the blocks are getting
printed accurately, are getting executed accordingly.
Let us go for this pattern printing.
These are the very common problems in our exams, so any will be taken from the keyboard as input.
There is a number of players.
If the number of player is equal to six, that means here will be having one, two, three, four,
five, six or six.
Number of players also can consider six is the number of here.
So to print this particular pattern here will be having some blank characters and then some esoteric
symbols will get printed.
But if I write only the blank characters, it will be not easy for us to count that.
How many blank characters are there?
So in place of blank, we have written here got so in the coding also we can replace this door by blank
if I want to get the final pattern here.
So here you have made one dressing table.
This is known as dressing table where we are trying to trace the logic of our code so far and the result
is but the pattern to be printed.
So I is a clear number or the height number.
It is ranging from one to six.
And here we are counting for each and every layer.
We are counting the number of blanks and the number of starts in this particular dressing table.
So here we are having five blank spaces and then one starts.
We have written five and one here we are getting four blank spaces and then three starts.
We have written this for entry here.
We are getting no blank spaces, but here we are having eleven starts.
So zero number of blank spaces and one number of starts or static symbols are going to get printed.
So from here we are supposed to get the logic for blank logic, for the esoteric symbol.
So what would be the logic for blank here?
You can find that I is increasing at the blank is decreasing.
So if you subtract this I from some fixed quantity, let it be in is equal to six.
So if you subtract this I from the six then obviously when the I'll be increasing that difference value
will be decreasing.
So anybody who are finding some logic that is something is increasing and another one is decreasing,
then obviously the value, the variable which is increasing should be subtracted from some fixed quantity
so that when the variable will be increasing, that difference value will be decreasing.
So that's why six minus one is five, six minus two is for six, minus three is six three and six,
minus six is zero.
So here the respective logic for the blank will be in minus eight.
Next one is increasing by one study, is also increasing by two.
So what we shall do if I is one start is a one I used to namaroff start will be three Isogawa five,
number of studies nine.
So we think that here the logic will be to start I minus one because doing two one two minus one is
one, two into three is six, minus one is five to into six is twelve minus one is eleven here.
So they hear the respective logic will be to start ie minus one.
So we have got the logic now we are going to implement it here.
So N is equal to in the input place and the number of players and then is equal to one report.
And when that this value of EI is less than equal to end, that means I'll be ranging from one to six
if the value up end is equal to six.
So here we are, put that on everything in the while loop construct.
So Jessica, we considering another control variable so will be equal to one.
And while G is less than.
So now what will happen for each and every player will be printing a certain number of blank characters
and then certain number of asterisk symbols.
Then you shall go for to continue to break.
So that will be the skeleton of our program.
So at first we're going to print some blank characters and then we're are going to bring some esoteric
symbols.
So how many blank characters we're having?
We're having N minus a number of blank characters.
So here we are putting this one as in minus one in minus eight.
So basically one day less than equal to N minus I print here.
We're printing this dot and end is equal to double double what means here we are just omitting the trailing
new line characters so all these dots will get printed in the same line.
So now again we are making this jiggle.
The one and G is less than equal to.
So here we are putting this start logic that is to start I minus one.
So we are putting this logic here and then print start and continuity will be there.
All the starts will get printed in the same row.
So that's why it's difficult to double double code.
So this is a print which will break the continuity.
So we'll be printing certain number of dark, certain number of starts.
So the next it'll be coming from the next line.
So that's why to break the continuity here to uprooting and putting out of the print segment.
So print function has been called here.
So now let me go for the execution.
We can find that if we give the value a six, I'm getting this pattern here.
So I think so I should make this one to start at minus one.
I should go for I increase.
So that statement is missing.
So let's go for this.
I increase.
So I is equal to eight plus one.
So here this has to be increased by one.
And also let us put the same in a while.
So what we shall do is that.
So Jay is equal to Jay plus one, so that statement is required, otherwise my program will fall in
in an infinite loop.
Jessica two plus one here.
So let's go for the execution.
So here you are, putting the value of an individual 060.
You're getting this pattern.
We're getting this.
So now if you put a different value for in here, if we put the value of any element, we are getting
the pattern like this, you can easily fill that.
One, two, three, four, five, six, seven, eight, 11.
So one, two, three, four, five, six, seven, eight, nine, 10, 11.
Yes.
So here we are getting this 11 number of layers and the pattern is getting printed accordingly.
So after writing any code, you should test your code with the multiple different values for inputs.
So let me check again.
One, two, three, four, five, six, seven, eight, nine.
Yes, we're having the nine layers, so each and every layer will be having this preceding dots and
then start.
So now in place of DOT, if you put a blank character, if you put a blank characters, and then the
pattern will be looking like this.
And the pattern will be looking like this in this way.
OK, now let us go for another example, so I want to bring this pattern like this, so any eleven dollars
a valuable and should be all here.
So it is the middle point.
I might be regretting it.
So let us at first go for the pattern.
So this is a pattern we are going to print.
So in the precinct we have written items ranging from one to 11 because element has been given and it
must be odd.
Otherwise this pattern will not have the symmetry if we have the invisibility even number.
So pattern will be will not be having the symmetry.
So now we are counting the number of dark, the stars, you know, so similarly with whatever we did
earlier.
So just consider this rule arbitrarily so that having four dots and three starts, so have written that
one has four dogs and three starts in this way, we filled up this DOT column and the star column.
So now let's go for the logic derivation.
You know that I is increasing throughout.
It is ranging from one to 11.
But here this is at first increasing, then it is decreasing.
So I cannot expect that same formula will work for the world hubs.
So that's why you are going for a separate formula, for this respective logic, for this dot printing
in the first up and in the lower up separately.
So how to do that?
Let us go for the.
Calculations here.
So if it is one, then it is zero, if it is true, then it is one.
If it is six, then it is five.
So it would be a minus one.
OK, now come to this point, if it is seven, it is four.
If it is eight, it is three.
If it is nine, it is two.
So that means I should subtract this from the from some fixed quantity so that when the value up I will
be increasing, the different value will be decreasing here.
So here we are having this I n is equal to eleven so eleven minus seven for eleven minus eight.
Three eleven minus ten.
One eleven minus eleven is zero here.
So here the logic will be in minus I.
Next one is that for this particular individual relevant.
My middle point is the middle, that is the sixth layer.
So how to get six here.
So that is very simple.
Eleven plus one, twelve by two is equal to six.
So that's why you are calculating another variable.
So the variable is getting initialized with six when the value of N is eleven, M stands for the middle
layer.
So now let us go for the calculation, the logic derivation for this start.
So this explosion's, whatever you are going to derive here can contain, I can contain N and also can
contain M here.
So let us go for this derivation.
So here you can find that I is increasing by one and start is decreasing by two.
So that means when the easier it must be subtracted from this fixed quantity so that different value
will be decreasing when the value of I will be increasing.
So let's go for the derivation.
So what is the logic are finding.
Just consider here.
So six minus one there is a five five in the two 502.
That is extent plus one that is eleven.
So I'm going to give you two clues.
Clue number one, when I is increasing, starting, decreasing, that means that I has to be subtracted
from some fixed quantity so that when the value up I will be increasing the difference value will be
decreasing.
There is no point.
Number one.
Point number two here is that here you can find that I is increasing by one, but the start is decreasing
by two.
So that different value has to be multiplied by some by two so that that difference will get decreased
the by the factor of two.
So six minus one, five to ten plus one eleven six minus four is two into two four plus one five six
minus six is zero two zero plus one one.
So here the formula will be to start here, the formula will be to start in minus I plus one.
Lost in this case, but having this one, there is this particular case.
So if I use seven stories to three, I use eight stories five so we can see that it is increasing by
one.
It is also increasing, but increasing by two.
So to multiplication factor will be there.
So that is our clue.
OK, now see.
So seven minus six, one, two, two, one, two, plus one is three nine minus six, what is that,
three in the two six plus one seven.
So that's why here the logic will be to start to start.
I might assume so to start at 8:00 a.m. So we are going to get here plus one.
So we have got the logic now how to implement the same.
So let me put this one here in the code I'm going to put here.
I'm going to object in.
So here you have got the logic now how to implement it, what we can do that after reading this valuable
when we are calculating that middle muswell.
So what does that mean?
Plus one whole.
OK, this entered the odd number of ballots, OK, next.
If I get it, then Im not what is what is the meaning of bigger than perhaps a lower eye, greater than
it means it is the lower half, so blank no blank will be equal to in the lower up in magnesite.
We got this one from here.
This one and four, they started having this formula.
So that is our starter, so here's what I think is equal to this formula else.
So we shall be going for this blank and blank is minus one, and the start will be equal to two minus
I thought to start in minus eight, plus one.
So if I get it, then there is a blank disaster or else there is a blank disaster.
So in this way, I've got this logic.
So now how many number of blanks will get printed, will get printed B number of and how many no upstarts
will get printed its numbers.
So in this way, I can easily implement my code.
So let me go for the cross-check.
If it is good, this code, I keep the value of it, then I'm getting this pattern.
So here you see we are having this dressing table is that we are having and it's the respective implementation.
You can easily find that how this code has got implemented.
So if you give the value, say, 13, I'm getting the pattern like this.
Let me count one, two, three, four, five, six, seven, eight, nine, 10, 11, 12, 13.
Yes, we are getting this our total number of layers here.
Obviously, layer number will be starting from one to 13 in this fashion.
So let me go for another execution if I make this one a seven.
We're getting this better like this.
OK, so if a user gives if user gives the event value for this end, then what will happen?
The pattern will not have the respect of symmetry here.
Now, I'm going to give you one example, one practice example here who just which has to be solved
by you.
So these are practice work.
We're having a program to display a pattern using loops.
So here the pattern is given here the pattern is given and here also prepared this dressing table you
want and here you are supposed to derive the logic and then that respective logic has to be implemented
using python coding.
So I'm giving this particular assignment as a practice work for your better understanding and for for
your better performance.
So please solve this problem.
I've made the problem partially done in the planning phase are now implemented using the Python code
and similar type of code already written.
So you are supposed to check that one out from this example.
So in this particular demonstration, we have discussed how to use a while loop in Python code.
Thanks for watching this video.