1
00:00:03,590 --> 00:00:04,370
Hello, everybody.

2
00:00:04,730 --> 00:00:05,840
Welcome back to the courts.

3
00:00:06,200 --> 00:00:10,070
In the last lesson, we covered basics of flowchart and solved a few problems.

4
00:00:10,550 --> 00:00:13,010
Today, we will solve a few different types of problem.

5
00:00:13,310 --> 00:00:16,350
And with the help of those problem, we will learn a new concept.

6
00:00:16,790 --> 00:00:18,400
So let us start today's class.

7
00:00:19,040 --> 00:00:25,860
So the problem statement is so the problem with treatment is you have to read to no E and the.

8
00:00:26,120 --> 00:00:28,060
And you have to print it as D.

9
00:00:28,400 --> 00:00:31,400
And you have to print five.

10
00:00:32,380 --> 00:00:32,950
DOMS.

11
00:00:34,460 --> 00:00:35,280
Of deform.

12
00:00:36,610 --> 00:00:46,060
A plus B, A plus duty, A plus to be A plus 40 and A plus 50.

13
00:00:47,750 --> 00:00:51,780
So let us first solve this problem in the most easiest and the simplest way.

14
00:00:52,790 --> 00:00:56,900
I will start my program and then I will read.

15
00:00:56,960 --> 00:00:59,120
Do no read.

16
00:00:59,210 --> 00:00:59,410
E.

17
00:01:00,070 --> 00:01:00,530
andI.

18
00:01:02,850 --> 00:01:04,320
And then I will print.

19
00:01:06,060 --> 00:01:06,780
A place de.

20
00:01:10,370 --> 00:01:12,620
Now, I will print a plus 2D.

21
00:01:18,290 --> 00:01:20,420
Now, I will print a plus 30.

22
00:01:25,170 --> 00:01:29,150
Now I will print a place for me.

23
00:01:30,420 --> 00:01:35,700
And finally, I will bring to my last home, which is a plus five.

24
00:01:37,950 --> 00:01:39,390
No way work is over.

25
00:01:40,170 --> 00:01:40,470
I will.

26
00:01:40,640 --> 00:01:40,960
Anyway.

27
00:01:42,440 --> 00:01:48,750
Program, so let us revise again what we have done, so the Brownlow's treatment was you have to read

28
00:01:48,840 --> 00:01:54,890
numbers A and B and you have to print five times of deform A plus D plus two, DTD four and five.

29
00:01:55,520 --> 00:01:58,160
So what I did, we start our program.

30
00:01:58,530 --> 00:02:04,080
Then we do numbers A&amp;E and we have printed the five times and then we have another program.

31
00:02:04,880 --> 00:02:08,960
So I hope by this time you might have noticed something strange with this approach.

32
00:02:09,380 --> 00:02:12,020
And if you didn't, then I have a question for you.

33
00:02:12,410 --> 00:02:13,880
So my question is very simple.

34
00:02:14,360 --> 00:02:16,880
What do you think of what might be the problem with this approach?

35
00:02:17,300 --> 00:02:19,490
I'm telling you this a problem with this approach.

36
00:02:19,610 --> 00:02:21,350
And you have to tell me what is the problem?

37
00:02:22,100 --> 00:02:23,720
Take your time and try to think.

38
00:02:25,180 --> 00:02:26,520
OK, let me give you a hint.

39
00:02:26,980 --> 00:02:29,640
In this case, I am printing just only five of them.

40
00:02:30,460 --> 00:02:32,170
So this approach is working fine.

41
00:02:32,620 --> 00:02:33,850
No problem at all.

42
00:02:34,390 --> 00:02:36,940
But what if we have to print one million item?

43
00:02:37,750 --> 00:02:38,890
Will this approach work?

44
00:02:39,850 --> 00:02:42,070
Would you use this approach to print one million item?

45
00:02:43,090 --> 00:02:43,870
Obviously, no.

46
00:02:44,500 --> 00:02:45,820
So I hope you got the idea.

47
00:02:46,390 --> 00:02:48,310
Let's come back to the question that I asked you.

48
00:02:48,910 --> 00:02:50,350
What is the problem with this approach?

49
00:02:50,890 --> 00:02:52,180
Yes, you got it right.

50
00:02:52,540 --> 00:02:55,580
This approach is very time consuming and inefficient.

51
00:02:56,660 --> 00:02:59,660
But why this approach is time consuming and inefficient?

52
00:03:00,020 --> 00:03:01,220
The answer is very simple.

53
00:03:01,310 --> 00:03:03,470
We are doing the same work again and again.

54
00:03:03,500 --> 00:03:04,910
Basically, repetition is dear.

55
00:03:05,300 --> 00:03:06,590
You can see the repetition here.

56
00:03:06,920 --> 00:03:08,810
We are printing again and again and again.

57
00:03:08,990 --> 00:03:10,630
This is just repetition of the work.

58
00:03:11,090 --> 00:03:16,550
If we look carefully, I can express any of their time as E-Plus idee.

59
00:03:17,180 --> 00:03:25,850
If the value of AI is one, if I equals when my time is a plus D, if I equals to my thumb is a plus

60
00:03:26,050 --> 00:03:26,430
Dody.

61
00:03:26,930 --> 00:03:29,600
And similarly, if the value of AI equals five.

62
00:03:30,020 --> 00:03:32,630
My time is a plus five.

63
00:03:33,650 --> 00:03:39,860
So basically we have to print a plus idee and the value of I will vary from one to five.

64
00:03:40,190 --> 00:03:42,380
So there are two ways to change the values of AI.

65
00:03:43,910 --> 00:03:47,840
So I told you there are two ways to change the values of AI.

66
00:03:48,140 --> 00:03:51,590
So the first way is that we ourself manually change the value of AI.

67
00:03:52,250 --> 00:03:56,940
But the problem with this approach is what would you do if you want to print one million item?

68
00:03:57,410 --> 00:03:58,990
So this approach will fail.

69
00:03:59,780 --> 00:04:07,460
The second key is that we will write some logic in such a way that the value of I will change automatically.

70
00:04:08,800 --> 00:04:11,200
Our logic will look something like this.

71
00:04:12,560 --> 00:04:14,090
Initially, my eye will be one.

72
00:04:15,480 --> 00:04:17,880
Then I will check is a list tonight.

73
00:04:17,930 --> 00:04:18,630
Close to five.

74
00:04:19,230 --> 00:04:19,650
Yes.

75
00:04:19,740 --> 00:04:20,670
One is less than I.

76
00:04:20,750 --> 00:04:21,450
Close to five.

77
00:04:21,900 --> 00:04:23,010
The condition is true.

78
00:04:23,340 --> 00:04:25,170
If the condition is true, what will I do?

79
00:04:25,800 --> 00:04:28,100
I will print E-Plus idee.

80
00:04:29,520 --> 00:04:33,640
So in this case, E-Plus Duvel reprinted and after printing Ableist Idee.

81
00:04:34,500 --> 00:04:35,220
What will I do?

82
00:04:35,730 --> 00:04:39,930
I will increase the value.

83
00:04:42,320 --> 00:04:45,830
Off I buy when?

84
00:04:48,110 --> 00:04:53,440
So the new really, if I becomes to, then I will check the condition again is to let the necklace two.

85
00:04:53,440 --> 00:04:53,710
Five.

86
00:04:53,810 --> 00:04:55,510
Yes, 20 plus 80.

87
00:04:55,580 --> 00:04:55,880
OK.

88
00:04:55,940 --> 00:04:57,400
So E-Plus truly gets printed.

89
00:04:57,950 --> 00:04:59,750
Then everything is the value if I buy one.

90
00:05:00,050 --> 00:05:02,870
So the new value if I is three then I will check my condition again.

91
00:05:02,960 --> 00:05:04,490
Estela's then goes to five years.

92
00:05:05,080 --> 00:05:05,330
Ben.

93
00:05:06,380 --> 00:05:09,320
Now the new value if I is for is for less than it goes to five.

94
00:05:09,380 --> 00:05:09,770
Yes.

95
00:05:09,860 --> 00:05:10,490
Ben diatom.

96
00:05:11,810 --> 00:05:14,740
Increase the value of I buy went to the new value of I is five.

97
00:05:15,460 --> 00:05:17,620
Check the condition Fifers Latona goes to five.

98
00:05:17,710 --> 00:05:26,110
Yes Pendelton E-Plus finally incremental value if I buy one to the new value if I is six is six less

99
00:05:26,110 --> 00:05:27,070
done it goes to five.

100
00:05:28,360 --> 00:05:28,810
No.

101
00:05:29,110 --> 00:05:31,350
So the condition is false.

102
00:05:33,570 --> 00:05:34,410
So what will I do?

103
00:05:34,440 --> 00:05:35,700
I will come out of the loop.

104
00:05:36,120 --> 00:05:37,630
Or who can say exit from the loop?

105
00:05:37,680 --> 00:05:38,940
Or you can see break the loop.

106
00:05:41,600 --> 00:05:47,420
So to implement the logic, the thing we need is called a loop, or you can see a cycle.

107
00:05:48,930 --> 00:05:50,870
So basically, there are three parts of a loop.

108
00:05:52,470 --> 00:06:01,320
So the first part is initialise the second Pardo's condition and the third parties update.

109
00:06:03,080 --> 00:06:04,190
So in the above case.

110
00:06:05,660 --> 00:06:06,690
I equals one.

111
00:06:07,340 --> 00:06:09,470
This is known as nasalization.

112
00:06:10,820 --> 00:06:12,160
This is the first part of a loop.

113
00:06:12,650 --> 00:06:14,630
Second part is to check the condition.

114
00:06:14,660 --> 00:06:16,790
So this is condition.

115
00:06:18,770 --> 00:06:20,540
And the third parties update.

116
00:06:20,780 --> 00:06:22,520
So this is update.

117
00:06:22,730 --> 00:06:24,320
We are updating the value of Ibai.

118
00:06:24,440 --> 00:06:24,710
When?

119
00:06:25,780 --> 00:06:28,320
So let us see, how does a loop look?

120
00:06:29,620 --> 00:06:30,280
How does.

121
00:06:31,990 --> 00:06:32,630
I loop.

122
00:06:35,150 --> 00:06:35,570
Look.

123
00:06:36,910 --> 00:06:38,970
So the first part is initialise.

124
00:06:40,180 --> 00:06:41,470
So I really wish lay something.

125
00:06:43,010 --> 00:06:45,620
The second part is to check the condition.

126
00:06:47,180 --> 00:06:48,500
Here we have it condition.

127
00:06:49,130 --> 00:06:55,070
If the condition is true, if the condition is true, then I will do some book.

128
00:06:56,520 --> 00:07:00,900
I will do some work, and after doing the book, I will update.

129
00:07:04,440 --> 00:07:10,260
After updating, I will check my condition again, if the condition is Viento, I will again do some

130
00:07:10,260 --> 00:07:13,050
work and then update that will check the condition again.

131
00:07:13,530 --> 00:07:16,500
If the condition is again through, then I will do some work again.

132
00:07:16,800 --> 00:07:20,810
Then I will update and then I will check the condition if the condition is false.

133
00:07:23,500 --> 00:07:25,790
Then I will exit or you can see.

134
00:07:26,120 --> 00:07:27,110
I will break my loop.

135
00:07:27,830 --> 00:07:28,730
Okay, great.

136
00:07:29,000 --> 00:07:32,270
Let us draw the flowchart for this problem using loops.

137
00:07:32,900 --> 00:07:34,310
So I will start my program.

138
00:07:36,210 --> 00:07:40,530
Then I will read two numbers, A and B.

139
00:07:42,260 --> 00:07:44,450
Now, the first part of Loop is to initialize.

140
00:07:44,780 --> 00:07:46,160
So I'm taking a variable.

141
00:07:46,520 --> 00:07:48,610
Let the name of the variable is a.

142
00:07:49,190 --> 00:07:51,890
So the variable AI is initialized to one.

143
00:07:53,120 --> 00:07:55,970
Now the next part of the loop is to check the condition.

144
00:07:56,690 --> 00:07:59,730
Sam checking is a list.

145
00:07:59,950 --> 00:08:00,860
Noriko's to five.

146
00:08:03,620 --> 00:08:06,140
So, yes, one is less than I did close to five.

147
00:08:06,770 --> 00:08:07,370
What will I do?

148
00:08:07,400 --> 00:08:08,510
The condition is true.

149
00:08:09,950 --> 00:08:11,750
Let's say I'm taking another variable.

150
00:08:12,230 --> 00:08:15,030
Dum dum equals a plus.

151
00:08:15,670 --> 00:08:16,970
I in two days.

152
00:08:19,150 --> 00:08:22,660
So the value of AI is one and time equals A plus D.

153
00:08:23,320 --> 00:08:24,100
Now what will I do?

154
00:08:24,130 --> 00:08:25,060
I will print them.

155
00:08:27,380 --> 00:08:32,290
So plus D will be printed after branding the them after doing the work.

156
00:08:32,350 --> 00:08:33,070
We will update.

157
00:08:33,490 --> 00:08:36,040
So I equals a plus one.

158
00:08:36,550 --> 00:08:38,200
And then I will check my condition again.

159
00:08:38,530 --> 00:08:41,890
So I equals I plus one means incremented the value if I buy one.

160
00:08:42,220 --> 00:08:48,580
Or you can see I equals I plus one means calculate this part and copy this part into this part.

161
00:08:49,330 --> 00:08:54,880
So first we really will read outages and will add the value of outages will go into Elitch's.

162
00:08:55,270 --> 00:08:57,790
So simply the value of I will increase by one.

163
00:08:57,820 --> 00:08:59,210
So this is the only way if I.

164
00:08:59,980 --> 00:09:01,690
And this will be new value.

165
00:09:03,100 --> 00:09:06,040
So a new value if I is two is to less than close to five.

166
00:09:06,190 --> 00:09:06,670
Yes.

167
00:09:07,150 --> 00:09:13,510
Through time equals plus truly printed them a plus truly incremental value if I went to the new value

168
00:09:13,510 --> 00:09:14,440
of a three.

169
00:09:14,980 --> 00:09:16,360
So it's three less than it goes to five.

170
00:09:16,460 --> 00:09:16,810
Yes.

171
00:09:17,110 --> 00:09:20,450
True democracy two duplicity gets printed.

172
00:09:20,860 --> 00:09:25,120
Similarly a plus for they will get printed as similarly a plus five will get printed.

173
00:09:25,180 --> 00:09:28,480
So the new elif I will become six is six less than it goes to five.

174
00:09:28,540 --> 00:09:29,530
So the condition is no.

175
00:09:30,950 --> 00:09:32,100
False, you can see false.

176
00:09:32,510 --> 00:09:36,480
So if the condition is false and I have rendered all their thumbs.

177
00:09:38,780 --> 00:09:41,510
My work is over now and I will end my program.

178
00:09:43,610 --> 00:09:47,270
And here you can see the loop on against this cycle.

179
00:09:48,110 --> 00:09:51,020
So this approach is way better than our previous approach.

180
00:09:51,320 --> 00:09:51,620
Why?

181
00:09:52,190 --> 00:09:57,020
Because if you want to print one million items, I only need to change just one thing.

182
00:09:57,380 --> 00:09:58,700
That is the condition.

183
00:09:59,880 --> 00:10:00,750
So what will I do?

184
00:10:01,290 --> 00:10:06,000
I will write her one million and one million items will be printed.

185
00:10:07,050 --> 00:10:08,640
So this approach is very efficient.

186
00:10:09,420 --> 00:10:10,380
Okay, great.

187
00:10:11,070 --> 00:10:14,910
So today we learned a new concept called Loop with the help of one problem.

188
00:10:15,240 --> 00:10:18,150
Do not worry if we are facing difficulty in understanding loops.

189
00:10:18,420 --> 00:10:19,920
This is completely normal.

190
00:10:20,120 --> 00:10:25,530
Initially, everyone faces difficulty in understanding loops and in fact, you should consider it in

191
00:10:25,530 --> 00:10:26,250
a positive way.

192
00:10:26,580 --> 00:10:31,590
It is a positive sign that you are learning new things which are challenging and difficult to understand.

193
00:10:32,700 --> 00:10:36,330
As far as I remember when I was learning about lubes.

194
00:10:36,780 --> 00:10:42,270
It took me nearly two days in understanding how I look and why we need loop.

195
00:10:43,080 --> 00:10:47,370
So if you understood just 30 percent of this lesson, you are way ahead of me.

196
00:10:48,090 --> 00:10:54,210
In the next class, we will be solving many questions based on loops because loops are very, very important

197
00:10:54,840 --> 00:10:57,180
and we will be using loops throughout this course.

198
00:10:57,720 --> 00:11:02,040
And I want to make sure that working off loops is crystal clear in your mind.

199
00:11:02,250 --> 00:11:05,450
So if you have any doubt, then first voice the next redo.

200
00:11:05,580 --> 00:11:09,030
And I am pretty sure that all of your doubts will be resolved.

201
00:11:09,660 --> 00:11:10,950
And if you still have doubts.

202
00:11:11,220 --> 00:11:12,270
Feel free to reach me.

203
00:11:12,420 --> 00:11:14,040
I will be more than happy to answer.

204
00:11:14,760 --> 00:11:16,390
So I hope you enjoyed Redistributor.

205
00:11:17,010 --> 00:11:18,420
I will see you in the next room today.

206
00:11:18,750 --> 00:11:21,740
Till then, enjoy C++ and thanks for watching.
