Hey, guys, what's up?
So in this session, we will learn a new concept called Loop.
So if you remember, we have done Leupen flowchart and pseudocode.
OK.
So this loop is exactly the same that we have done.
So I am just we are doing a quick recap of how a loop work.
So first of all, I was having an initialization first.
We will initialize.
Then I will have a condition.
If this condition is true.
So if this condition is true, then I will do some work.
If this condition is true, I will do some work and then I will update.
Then I will update and then after updating.
I will check the condition again if the condition is again through.
I will again do some work.
And then I will update again, again, I will check the condition, but if condition is false.
So if the condition is false, I will come out of the loop.
So come out of the loop.
So this is how a loop looks.
OK, now let's see.
So, for example, our task is to print hello five times.
I want to print halloo five times.
So what I can do is I can write Seo Tolu.
And I will write it five times.
So see out.
Hello.
So now.
Hello.
We printed five times.
OK.
I will just copy paste this line four more times.
So in total, HelloWallet printer five times.
But my task is to printed 500 times.
So we have to right?
We have to compete for 99 times to make it 500.
Now I'm saying it.
You have to print hello one million times.
So obviously, by this time you might have noticed that this approach is very inefficient and time consuming.
So what we can use, we can use a loop.
So what will I do?
I will say, hey, Lupe ran 500 times.
Loop run 500 times, and each time this loop is running, I will bring telo.
So this loop is running 500 times, and each time I am bending.
Hello.
So hello.
Will be printed five hundred times.
OK, so let's see.
So if you remember in pseudocode, I was having.
Via loop.
So here we are also having while loop.
So how does a code of why Loop looks like.
So let's take a variable.
I saw in time equals one.
This is my initialization.
While some condition will be there.
And then some oblation will be.
And here I will do my work that I want to do.
So let's see.
So let us spend hello.
500 times.
So I'm making a new file.
Leard Snam, This Fire Les.
While.
Not CBB.
OK.
OK, so what we want to do is I want to print hello 500 times.
So, OK, so let's first of all, print hello five times.
So N.T. equals one.
So this was my initialization.
Now I will check the condition.
So while vial is a key word here.
OK.
So while I lasdun articles two five.
And I will update here a plus plus a plus plus means increment of a little five by one, it is same
as I equals a plus one.
Now each time this loop is learning, I have to print.
Hello.
So see you out.
Hello.
So this is all that we have to do.
So let's put in our program.
So we'll see out.
Hello and Lane.
So what is the error?
OK, so.
Analyze this.
Now let us earn it again.
So as you can see, Helo's printed five times.
Now let's see how it is working.
So first of all, this is my initialization.
So this is initialization.
First part of the loop.
This is my condition.
I list an order close to five.
This is my condition.
And this is my oblate.
OK.
So all three combatants of a loop are present.
So how many times this little building.
So initially I was when and in the condition I am checking while I left, then we're close to five.
So this is my condition.
And each time I am incrementing the value of I buy one.
So this means I equals a plus one.
This is just another way of writing.
I quote I plus one.
OK.
So initially the value of fi is one.
And each time I am incrementing the value if I buy one.
And this low in this condition.
So with the help of these three, my loop will run five times.
OK.
Initially, the value of fire is one each time the slope is running, I am incrementing the value of
fire by one.
And my condition is I list in order close to five.
So in total, this loop will run five times.
And each time this loop is running, I am printing.
Hello.
So in total, hello will be Brendel 500 times.
OK, so what if I remove it close to a list in five?
How many times?
Now this loop will run.
So this loop will run four times.
Let's see.
So Hillary is getting printed four times by.
So when the value of AI is when this condition is true.
Hello teleprinter.
So when when I equals two to this condition will again do so.
Hello.
Blueprinted.
Two times when I was three.
This condition is again to trace.
Less than five.
So hello.
Ilive rendered again.
So three times.
Hello.
When I equals four four it is less than five.
This condition is again true.
Harrowingly brain dead one more time.
So lower spending.
Hello is getting rendered four times when I equals five.
This condition will become false because five is not less than five.
This is wrong.
So this condition will become false and I will reach line number 14.
OK, so hello, loop under four times.
Now, let's take one more example.
So suppose.
Now, if I want to print hello 500 times.
So the only change that I have to do, I will right here.
500 or let's say five thousand.
Fifty thousand.
OK.
So this is the benefit of the loop.
This is the advantage of a loop.
So listen.
So as you can see, our program is running five thousand times.
Now, let's see one more thing, how this halloo is getting printed.
Five things.
So my code is very simple and I equals one.
While I is less than or equal to five, I am printing hello.
And then I am incrementing to vilify my one.
So let's say, hey, is my output.
So this is my output.
So initially the value of AI is one.
OK, so AI is one.
The condition is one less 10 articles to five.
Is one less than or close to five?
Yes, the condition is true.
You will come inside the loop.
You will print.
Hello.
So in my output.
Hello.
Is getting printed.
Then you add incrementing the value if I buy one.
So the new value if I will become to and from this broker to you will again reach here.
Now you will check the condition again is to less than or equal to five.
Yes, the condition is true.
You will again print.
Hello sir.
Hello.
Will be printed again.
Now you will increase the value if I buy one.
So a new value of fly is three.
Now you will again check the condition.
So is three list in order close to five.
Yes, the condition is true.
So will you will come inside and you will print.
Hello.
So hello.
Is getting printed one more time.
And now you will increase the value of I buy one.
So the new value of five is No.
Four.
Now you will again reach here and you will check the condition again.
So is for less than not close to five years.
The condition is again true.
You will print hello again.
So hello will be printed again.
Now you will increase the value of I by one to the new value of I will become forward.
Now you will check the condition again.
So is five less than articles to five.
Yes, five is less than articles to five.
So welcome Inside the Loop.
And you will print.
Hello.
So hello is getting Brender.
One more time.
And then you will increase the value of I.
So I.
It was six.
Now you will check the condition again.
So is six.
Less than Orchestre five.
No.
So this condition will become fallers when I.
Becomes six.
So since this condition is false, I will not go inside the loop.
I will reach at this line.
OK.
And this is my output.
Hello.
Is getting printed five times.
OK.
So this is how a loop works.
Now let me tell you the concept of infinite loop.
OK.
So what if I remove this update condition?
What will happen if I remove the subject condition?
So let's see.
So you can see hello is getting printed in finite times, so this loop will never stop.
This loop will never stop.
It will keep on executing.
So why this helo is getting printed infinite number of times.
So let us try to understand why it is so OK, so this will not stop.
You have to stop it from here.
Now, let's see what is happening in.
So our record is in question.
While I is less than or equal to five, then you are printing hello here.
And then we have commandeered this line I E-Plus plus.
So let's see what happens.
So here is my output.
First of all, I will check my equation.
OK.
So I equals one.
Now I will check every condition is one less than close to five.
Yes.
The condition is to go inside the loop.
Brent.
Hello.
OK.
I am printing.
Hello.
So this line is a comment.
We will not do anything now from this record.
I will check the condition again.
So the value of AI is again one.
So one is less than it goes to five.
Yes.
Have the condition is true.
Brent, hello again.
Condition is true.
Brent.
Hello again.
The condition is true.
Brent.
Hello again.
The condition is true.
Brent, hello again.
The condition is true.
Brent.
Hello.
So I will always be one since I is always one and one and one is always less than close to five.
So this condition is always true.
True, always.
So this condition is always true.
And that is that is reason.
Hello.
Really.
Hello.
We keep bringing in finite number of times.
OK, so that's that is there is an updated condition is important.
So if you would an outright W8 condition or the right update condition wrong, our loop will run in
finite number of times.
OK, now let us.
Right.
Wrong loop.
So instead of incrementing, I plus plus, what if I'm updating, but I am doing it wrong, I am decreasing
the value if I buy one in this case also my loop will run and finite number of times.
Let's see.
So as you can see, again, this loop is an infinite loop, Hallowell get printed and finite number
of times.
Now, we have written W8 condition here.
So why this loop is infinite running infinite number of times in the previous case?
I commended W8 condition.
So there it is, the reason my condition was always true.
OK, Martin.
We have an updated condition then also my loop is running in finite number of things.
So what is happening here?
Let's try to understand.
So in previous case, Lupe was running in funny at times because we have commented out IWD condition.
But in this case, we have written ablate condition.
Then also my loop is running in finite number of times, socio telo.
Now we are decreasing the value of fire by one.
OK, so here's my output.
I equals one.
So is one less than close to five.
Yes, the condition is true.
Brent hello.
So is he out?
Hello.
The keys, the radio five.
I once knew a little five will become zero.
Now check the condition again is zero listing close to five.
Yes.
Zero is less than out of close to five.
So I will come inside the loop and I will print.
Hello again.
Now the keys to vilify by went to the new l'oeil five becomes minus one.
And now you will check the condition again.
So is minus one.
Let's 10 articles to five.
Yes, the condition is true.
You will come inside the loop and you will print.
Hello again.
Now the keys to vilify by one.
So new.
Well, if I is minus two again you will check the condition head.
Will we get printed.
Now I equals minus three.
Then minus four.
And so on.
OK.
So basically, I will never become close to six.
OK, so the value of FI is decreasing.
And what should happen?
The value of I should have increased.
But in this case, the vilify is decreasing and hence the value of I will never become greater than
five since the very five will never become good.
Then five.
This loop will always be true.
And that is the reason hello will get printed in finite number of times.
In previous case.
In previous case, this condition was true because we have not returned the update statement.
OK.
In this case, I believe statement was missing.
Notice the reason this condition was always true.
But in this case, we have written the updated condition.
But we have written the wrong update condition.
So that is there is in this loop is always through.
OK.
Now, there is one more way to make our loop.
Always true.
So what we can do.
OK.
Sorry.
See old.
So basically, the main concept is my loop will run an infinite number of times only when my condition
is always true.
OK, so this is the mean idea of running a loop and in a number of games.
What do you do?
Make the loop always.
So wild when one means through.
So vilely means run the loop infinite number of times.
So this loop will run infinite number of times.
Let's see.
So as you can see, this loop is also running in finite number of times.
OK.
Now, why this little boy is running and fired a number of times to.
So the logic is very simple, Viall when I am printing hello.
So if you look carefully at the above example, my loop will run in finite number of times if the condition
is true, all these.
Similarly, hair, my lube with was also running in finite a number of times because this condition
was always true.
So the main concept is any loop will run in finite number of times if the condition is always true.
So if the condition is always through, my loop will run in finite number of times.
So I have already told you on that any positive value, any positive value means through and the zero
means false.
So one means through survival, through.
So this condition will always be true and will be printed in finite number of times.
OK.
So what will happen instead of writing one here?
I write five.
Then also this loop will end in fact number of times because five means through.
Similarly, you can write three, seven, eight anyway.
And if we write vilely, zero zero means Falls City out.
Hello.
So if you will run this, my loop will not run.
So hello will not be Brender because this is false.
Since the condition is false, I will reach here.
I will not go inside the loop.
So let's see.
So Insitute of One here you can write anyway, Lou.
For example, seven.
Because seven is a positive number.
Has the condition a lot less brutal.
So the loop is running fine.
Number of times.
Now, let us slide here.
Zero.
So while zero zero means false, since the condition is false, I will not go inside the loop.
I will directly commit line number one.
OK, so I will likely come here.
Line number two.
OK.
So nothing is getting printed.
Great.
Now, our task force, we have to print hello.
We have to print hello.
Let's say 2000 times our problem was started.
So our problem was started from 5000 times.
We have to print our low 5000 times.
So logic is very simple.
Take a video, Ballay.
And you should either to one.
Right.
The condition condition is very simple.
While a listing goes to five and just increment the radio five by one.
So I bless plus.
Now, this loop is perfect.
So HelloWallet Carpenter.
Five thousand times.
So hello is getting Brender.
Five thousand times you can scroll up if you want.
And if you have extra time, you can also countered.
OK.
So this is the mean idea of a loop.
No incoming weirdos from what we will do.
We will solve many problems with the help of Loop to get a better understanding how the loop is working.
OK, so that is all for this video.
Thank you.