1
00:00:01,980 --> 00:00:03,480
Hey, guys, what's up?

2
00:00:03,930 --> 00:00:10,610
So today we are going to study a new topic called Scope of Lady of.

3
00:00:16,720 --> 00:00:20,290
So, for example, if my code is in DeMain.

4
00:00:23,840 --> 00:00:26,640
Suppose I have a variable and I.

5
00:00:27,450 --> 00:00:29,380
And suppose I have a for loop.

6
00:00:32,710 --> 00:00:39,040
And I'm doing some work here, and for example, if I create a variable G inside the for loop.

7
00:00:40,990 --> 00:00:41,210
OK.

8
00:00:41,310 --> 00:00:46,120
And then I am printing the value of G outside the for loop.

9
00:00:47,050 --> 00:00:48,640
So my question is.

10
00:00:49,990 --> 00:00:51,180
Is this correct?

11
00:00:52,720 --> 00:00:54,960
So is this code correct or not?

12
00:00:57,160 --> 00:00:58,690
So what is happening here?

13
00:00:59,170 --> 00:01:06,170
You declared the variable G inside the for loop and you are trying to access the G outside the for loop.

14
00:01:06,690 --> 00:01:08,230
So Compiler will give us added.

15
00:01:10,220 --> 00:01:18,140
And what error compiler will give compiler will say, I don't know, Compiler will say, I don't know

16
00:01:18,140 --> 00:01:18,650
what DG.

17
00:01:19,970 --> 00:01:22,710
I don't know where this G.

18
00:01:23,670 --> 00:01:23,960
Why?

19
00:01:24,380 --> 00:01:30,970
Because the existence of G is between these brackets, these curly brackets.

20
00:01:32,370 --> 00:01:32,630
OK.

21
00:01:32,970 --> 00:01:36,040
You have declared a variable J inside the for loop.

22
00:01:36,990 --> 00:01:43,870
And since this J is declared inside the for loop, so its existence is between these calibrate codes.

23
00:01:43,890 --> 00:01:51,510
Only if you are trying to access if you will try to access this J outside this Becket's then compiler

24
00:01:51,510 --> 00:01:55,320
will say, hey, I don't know what this G.

25
00:01:56,530 --> 00:01:56,780
OK.

26
00:01:57,360 --> 00:02:04,390
So if someone ask you what is scope of G, so what is the scope of variable G?

27
00:02:04,680 --> 00:02:05,530
So the scope of J.

28
00:02:05,640 --> 00:02:08,130
Is between these curly brackets.

29
00:02:09,920 --> 00:02:11,300
Outside these Carlebach kids.

30
00:02:12,360 --> 00:02:14,160
Compiler don't know where d.g.

31
00:02:15,090 --> 00:02:15,430
OK.

32
00:02:17,190 --> 00:02:17,970
Now, let's see.

33
00:02:19,600 --> 00:02:22,800
Okay, so let us write some code to get a better understanding.

34
00:02:27,040 --> 00:02:31,180
So let's name it Scope Nazi, BP.

35
00:02:46,110 --> 00:02:50,370
So I will show you some exciting things.

36
00:02:51,180 --> 00:02:54,310
Suppose I have a variable index equals 10.

37
00:02:55,740 --> 00:02:56,040
OK.

38
00:02:56,460 --> 00:03:02,220
Now if you will create the same variable and X, then compiler will show you edit.

39
00:03:02,730 --> 00:03:03,240
Let's see.

40
00:03:06,210 --> 00:03:13,650
So the compiler is showing us error and error is that you can't have two variables with the same name.

41
00:03:15,450 --> 00:03:17,100
So X equals 10.

42
00:03:17,700 --> 00:03:20,720
And you are again making a variable and X.

43
00:03:21,000 --> 00:03:25,680
So compiler will say, hey, buddy, you can't have two variables with the same name.

44
00:03:27,060 --> 00:03:28,110
But let me show you.

45
00:03:30,300 --> 00:03:31,440
Some interesting things.

46
00:03:31,500 --> 00:03:41,140
So what I will do for and I equals zero I less than two five.

47
00:03:41,520 --> 00:03:42,680
I bless, bless.

48
00:03:44,100 --> 00:03:48,570
And let's see here I am making a variable again with the same name X.

49
00:03:49,830 --> 00:03:51,320
Let's say your index equals I.

50
00:03:52,440 --> 00:03:55,920
And then I am printing the value of X.

51
00:03:58,720 --> 00:03:59,260
And Len.

52
00:04:02,250 --> 00:04:02,510
OK.

53
00:04:04,340 --> 00:04:07,700
So what do you think Combiner will show us at it or not?

54
00:04:09,340 --> 00:04:10,820
OK, let's do one more thing.

55
00:04:11,540 --> 00:04:15,260
Let us spend the value of X, also see outtakes.

56
00:04:16,220 --> 00:04:18,230
Let's see what will be our output.

57
00:04:18,830 --> 00:04:24,290
So my first question is whether compiler will show us error at line number 10 because we are creating

58
00:04:24,290 --> 00:04:25,120
a variable X.

59
00:04:25,790 --> 00:04:27,800
And the name already exists.

60
00:04:27,980 --> 00:04:32,120
We are already having the same variable variable with the same name.

61
00:04:33,670 --> 00:04:34,330
So let's see.

62
00:04:38,400 --> 00:04:40,930
No, the compiler is not giving us added way.

63
00:04:42,210 --> 00:04:46,590
Let's try to understand why the compiler is not giving this error in the previous case.

64
00:04:47,780 --> 00:04:49,020
Kambala showed us at a.

65
00:04:51,020 --> 00:04:52,430
So just try to focus.

66
00:04:52,850 --> 00:04:58,870
What was the last case in Texaco's 10 and thanks so come by, Lessie.

67
00:04:59,570 --> 00:05:02,030
Hey, you can't have two variables with the same name.

68
00:05:02,150 --> 00:05:07,610
I say, OK, now here I am again, having variables with the same name.

69
00:05:07,790 --> 00:05:12,890
Then Weida come by Lisen or jingoes error because they have different scope.

70
00:05:13,640 --> 00:05:22,610
The scope of this variable is between this Blackard and this Blackard, whereas the scope of this variable

71
00:05:22,640 --> 00:05:26,030
X is between this Blackard and this Blackard.

72
00:05:27,600 --> 00:05:30,080
OK, so the main reason is different.

73
00:05:30,140 --> 00:05:30,650
Schoop.

74
00:05:32,910 --> 00:05:35,740
They're too variable, X has different scope.

75
00:05:37,060 --> 00:05:40,330
OK, so these two variables X are different.

76
00:05:40,720 --> 00:05:45,040
And the main reason is because of the different scope.

77
00:05:48,470 --> 00:05:50,120
OK, so this variable.

78
00:05:51,530 --> 00:05:52,610
Let me clear all this.

79
00:05:57,990 --> 00:06:00,100
So this variable X is different.

80
00:06:03,110 --> 00:06:05,060
This variable X is different.

81
00:06:07,000 --> 00:06:07,960
And what is the reason?

82
00:06:08,230 --> 00:06:09,760
Because they have different scope.

83
00:06:13,630 --> 00:06:18,250
The last example was and X equals 10 and X.

84
00:06:18,670 --> 00:06:21,940
They both were not different because their scope was him.

85
00:06:22,890 --> 00:06:23,200
OK.

86
00:06:23,680 --> 00:06:25,210
Their scope was same.

87
00:06:25,240 --> 00:06:26,230
So come by level.

88
00:06:26,560 --> 00:06:27,340
Show us at it.

89
00:06:27,670 --> 00:06:29,500
But here, their scope are different.

90
00:06:29,590 --> 00:06:32,020
So they will be treated as different variables.

91
00:06:33,720 --> 00:06:33,960
OK.

92
00:06:34,060 --> 00:06:36,550
So they will be treated as different variables.

93
00:06:39,480 --> 00:06:41,700
One more thing that I want to tell you is.

94
00:06:43,870 --> 00:06:44,860
Let's see the output.

95
00:06:45,130 --> 00:06:46,000
Where does my output?

96
00:06:49,710 --> 00:06:51,600
So now I put this coming out with this.

97
00:06:51,720 --> 00:06:53,160
Now let's see how it comes.

98
00:06:59,800 --> 00:07:02,390
So first of all, I told you, this is different takes.

99
00:07:02,860 --> 00:07:10,060
So what I'm doing are variable, I is varying from zero to five and the value of I assigned to X and

100
00:07:10,060 --> 00:07:11,320
then I am printing X.

101
00:07:11,770 --> 00:07:14,470
So zero to four is expected.

102
00:07:16,140 --> 00:07:16,850
Zero to four.

103
00:07:18,170 --> 00:07:19,040
Will remain output.

104
00:07:19,400 --> 00:07:20,660
This is the output of loop.

105
00:07:21,390 --> 00:07:21,570
OK.

106
00:07:21,650 --> 00:07:23,770
So what is the output of loop output of Lopez?

107
00:07:23,840 --> 00:07:24,380
Zero.

108
00:07:24,500 --> 00:07:26,540
One, two, three and four.

109
00:07:27,470 --> 00:07:29,300
Now, focus on line number 14.

110
00:07:31,040 --> 00:07:33,050
So the value of X is ten.

111
00:07:33,770 --> 00:07:38,080
If we treat this X and the value of X is four.

112
00:07:38,510 --> 00:07:44,720
If I treat this X, so vich values getting printed, then why not four?

113
00:07:45,590 --> 00:07:50,960
Because this variable X doesn't exist after these Beckert.

114
00:07:52,510 --> 00:07:55,900
OK, so this X is this X?

115
00:07:59,120 --> 00:07:59,440
OK.

116
00:08:00,570 --> 00:08:01,650
Just one more time.

117
00:08:06,710 --> 00:08:10,700
First thing first, the sex and the sex are different.

118
00:08:11,520 --> 00:08:11,830
OK?

119
00:08:12,290 --> 00:08:14,840
What is the output of the loop, aka the loop is zero.

120
00:08:14,840 --> 00:08:16,130
One, two, three and four.

121
00:08:16,800 --> 00:08:18,740
Now, with each line number 14.

122
00:08:19,100 --> 00:08:20,000
So red line number four.

123
00:08:20,050 --> 00:08:20,170
Ding!

124
00:08:20,240 --> 00:08:21,740
I am bringing the value of X.

125
00:08:22,470 --> 00:08:25,640
OK, so which X is this.

126
00:08:25,760 --> 00:08:27,140
This one or this one.

127
00:08:27,440 --> 00:08:34,250
So obviously this one to be Y because this X exists only between this and this.

128
00:08:35,690 --> 00:08:39,560
So obviously this X is this one.

129
00:08:40,070 --> 00:08:40,830
Now what div.

130
00:08:44,660 --> 00:08:47,060
Now, what if I remove and from here?

131
00:08:49,810 --> 00:08:52,900
What will happen to this is normal conditions.

132
00:08:53,770 --> 00:08:54,220
Let's see.

133
00:08:57,590 --> 00:08:59,750
So I would argue this is zero, one, two, three, four.

134
00:08:59,780 --> 00:09:02,890
And again, four in the last example, it was 10.

135
00:09:03,860 --> 00:09:04,200
OK.

136
00:09:04,520 --> 00:09:05,810
Now let's see what is happening here.

137
00:09:09,500 --> 00:09:11,570
So there is no confusion in this.

138
00:09:12,110 --> 00:09:13,490
So there is no confusion.

139
00:09:14,060 --> 00:09:14,390
Why?

140
00:09:14,630 --> 00:09:17,200
Because there is only one X and Y.

141
00:09:17,300 --> 00:09:19,160
Can I use this X between this X?

142
00:09:19,430 --> 00:09:26,400
Because the scope of this X is between this and this and full loop comes between this and this.

143
00:09:27,080 --> 00:09:33,020
OK, so I can use X inside the loop so X equals I and bring the value of X so zero.

144
00:09:33,020 --> 00:09:33,770
One, two, three, four.

145
00:09:34,950 --> 00:09:37,250
Of this, now I am bringing eggs.

146
00:09:37,690 --> 00:09:38,500
So this eggs.

147
00:09:39,720 --> 00:09:40,520
Should be good, Brender.

148
00:09:40,710 --> 00:09:42,840
But this X and this X is same.

149
00:09:43,110 --> 00:09:46,620
If I am changing the value of X, this X value will also change.

150
00:09:46,650 --> 00:09:47,690
Basically the same.

151
00:09:48,970 --> 00:09:50,040
They are same.

152
00:09:50,670 --> 00:09:53,130
So since they are saying my output will be for.

153
00:09:54,150 --> 00:09:55,890
Because the law desperately affects this food.

154
00:09:56,400 --> 00:09:56,940
One more time.

155
00:10:03,820 --> 00:10:06,910
And this woman, this ex and this ex Assim.

156
00:10:08,430 --> 00:10:08,700
OK.

157
00:10:09,220 --> 00:10:10,660
I am changing the value of X.

158
00:10:10,690 --> 00:10:11,460
X equals I.

159
00:10:12,130 --> 00:10:14,260
So this value will be changed.

160
00:10:15,350 --> 00:10:20,150
And finally, the updated value, which is full, will get printed.

161
00:10:23,170 --> 00:10:24,850
OK, now one more thing.

162
00:10:28,000 --> 00:10:32,880
What will happen if I try and print you out?

163
00:10:33,830 --> 00:10:34,680
Let's say I.

164
00:10:38,780 --> 00:10:50,180
So I think Compiler will show us a way, because this eye is a part of for loop and hence the scope

165
00:10:50,180 --> 00:10:54,620
of variable eye is between this Blackard and this record.

166
00:10:55,280 --> 00:10:58,400
And I am using it outside the for loop.

167
00:10:58,870 --> 00:11:00,760
So Compiler should source it.

168
00:11:01,520 --> 00:11:02,750
And I should all cut.

169
00:11:05,430 --> 00:11:05,630
OK.

170
00:11:05,870 --> 00:11:06,590
So there it is.

171
00:11:07,580 --> 00:11:10,130
That is very simple, Combiner don't know what is a.

172
00:11:12,280 --> 00:11:16,240
OK, now let's see some more interesting things.

173
00:11:19,220 --> 00:11:21,800
So you have to tell me what will be my output?

174
00:11:22,370 --> 00:11:23,480
So InterMune.

175
00:11:27,560 --> 00:11:32,360
And it's suppose now there's a for loop.

176
00:11:35,830 --> 00:11:41,430
There's something written, and now I'm printing the value of X.

177
00:11:42,670 --> 00:11:44,140
So what will be my output?

178
00:11:46,400 --> 00:11:46,650
OK.

179
00:11:46,750 --> 00:11:48,910
So tell me where to live, my output.

180
00:11:50,170 --> 00:11:51,520
So the answer is very simple.

181
00:11:51,880 --> 00:11:53,440
Output will be a Garveys value.

182
00:11:54,340 --> 00:11:55,370
Sodrel will be at that rate.

183
00:11:55,470 --> 00:11:57,480
When do I have not given X anyway, Lou?

184
00:11:57,850 --> 00:12:01,000
So when you will train for index, you will get a Gadsby's value.

185
00:12:01,450 --> 00:12:03,730
This question is not at all related to scope.

186
00:12:04,720 --> 00:12:07,270
I just give this cushion to open your mind.

187
00:12:08,200 --> 00:12:08,410
OK.

188
00:12:08,710 --> 00:12:11,200
So what value output are garbage value.

189
00:12:12,740 --> 00:12:16,210
Now you have to tell me if I try and print.

190
00:12:17,320 --> 00:12:17,890
Let's say.

191
00:12:19,050 --> 00:12:19,750
And I mean.

192
00:12:24,790 --> 00:12:33,310
And eye for and eye equals zero, eye less than, let's say, five.

193
00:12:33,980 --> 00:12:34,900
I bless, bless.

194
00:12:35,700 --> 00:12:40,330
I am doing some work here and now I am finding the value of a.

195
00:12:41,500 --> 00:12:43,000
So widely we might output.

196
00:12:45,630 --> 00:12:51,810
So you have to tell me whether there will be another compilation error will occur or otherwise.

197
00:12:51,870 --> 00:12:53,610
Tell me what will be Moudud?

198
00:12:55,660 --> 00:12:59,740
OK, so I think compilation that I will not be there.

199
00:13:00,120 --> 00:13:00,390
Why?

200
00:13:01,150 --> 00:13:04,870
Because this I and this I, they both are different.

201
00:13:05,050 --> 00:13:05,230
Why?

202
00:13:05,230 --> 00:13:05,770
They are different?

203
00:13:05,800 --> 00:13:07,120
Because they have different scope.

204
00:13:07,960 --> 00:13:12,670
The scope of this eye is this record and this record.

205
00:13:12,790 --> 00:13:20,020
The scope of this eye is this record and this record, since these two eyes are different.

206
00:13:20,320 --> 00:13:21,400
They are independent.

207
00:13:23,260 --> 00:13:25,920
Now, add this line, I am bringing the value of I.

208
00:13:26,530 --> 00:13:34,990
So at this point of time, only, only when I exist, only when I exist.

209
00:13:35,440 --> 00:13:36,260
This I.

210
00:13:36,940 --> 00:13:38,230
Does not exist.

211
00:13:39,070 --> 00:13:39,890
This I.

212
00:13:40,180 --> 00:13:46,300
Does not exist outside records of loop.

213
00:13:48,300 --> 00:13:48,500
OK.

214
00:13:48,590 --> 00:13:49,790
So this I.

215
00:13:50,770 --> 00:13:52,510
Doesn't exist at this line.

216
00:13:53,440 --> 00:13:54,490
OK, so add this line.

217
00:13:54,550 --> 00:13:55,680
I have only one eye.

218
00:13:55,840 --> 00:13:57,040
Which is this one.

219
00:13:59,600 --> 00:14:06,250
Since I have only Varnay, I will print the value of the day and hence my would probably be a God visually.

220
00:14:09,040 --> 00:14:09,350
OK.

221
00:14:11,070 --> 00:14:13,190
So if you don't believe me, I can show you.

222
00:14:15,240 --> 00:14:21,630
So what I will do here, I just have to create two variables, and I know at this point of time only

223
00:14:21,630 --> 00:14:23,070
when I exist in the memory.

224
00:14:25,620 --> 00:14:26,910
Now, when I did this.

225
00:14:27,420 --> 00:14:29,070
Now they exist to in the memory.

226
00:14:29,100 --> 00:14:34,520
But those two, why they are different, why they're different because they have different scope.

227
00:14:36,710 --> 00:14:37,080
Okay.

228
00:14:38,880 --> 00:14:41,110
Now, I am not doing anything inside the loop.

229
00:14:42,870 --> 00:14:45,570
And here I am bringing the value of a.

230
00:14:49,230 --> 00:14:58,490
Now, again, headline number 23, there exist only one eye in the memory, and this is that I had somehow

231
00:14:58,530 --> 00:15:00,930
butchered we are garbage value simple.

232
00:15:05,880 --> 00:15:07,360
So the output is our garbage value.

233
00:15:08,350 --> 00:15:09,790
This was also the same case.

234
00:15:11,320 --> 00:15:12,400
Now, let's go into doubt.

235
00:15:18,910 --> 00:15:22,200
So when here I was having an thanks.

236
00:15:22,810 --> 00:15:23,900
So what was happening here?

237
00:15:25,540 --> 00:15:31,290
At this point of time, line number seven, there exist only 16 in the memory lane, number 10.

238
00:15:31,420 --> 00:15:34,660
They exist to extend their memory, but they both are different.

239
00:15:34,750 --> 00:15:35,350
Why different?

240
00:15:35,410 --> 00:15:38,860
Because different scope now at lane number 14.

241
00:15:39,280 --> 00:15:42,210
I am bringing the X at lane number 14.

242
00:15:42,280 --> 00:15:49,420
They exist only when X and the memory Y because this X as soon as this X will cross it boundary.

243
00:15:50,880 --> 00:15:52,330
It will not exist, okay?

244
00:15:52,650 --> 00:15:54,300
It will die or it will not exist.

245
00:15:55,020 --> 00:15:56,000
So headline number fording.

246
00:15:56,190 --> 00:15:58,860
They exist on live next in their memory, which is this one.

247
00:16:00,110 --> 00:16:05,930
But as soon as you reach line number 16, you are printing them well, if I come by, I will say I don't

248
00:16:05,930 --> 00:16:06,350
know I.

249
00:16:06,920 --> 00:16:07,760
Why you don't know?

250
00:16:08,000 --> 00:16:09,710
Because I exist.

251
00:16:10,850 --> 00:16:15,250
Well, the for loop, as well as the for loop end, and it doesn't exist in the memory.

252
00:16:18,440 --> 00:16:18,610
OK.

253
00:16:19,180 --> 00:16:24,150
So I hope you've got some feel of what is its global variable.

254
00:16:25,150 --> 00:16:29,020
So what we will do now and next we do I will cover what is global variable.

255
00:16:29,100 --> 00:16:32,370
And then next we do I will cover some more questions on scrollbar.

256
00:16:32,380 --> 00:16:32,890
Very well.

257
00:16:32,980 --> 00:16:34,420
And global variable mix.

258
00:16:35,590 --> 00:16:35,910
OK.

259
00:16:37,100 --> 00:16:41,590
So this is it for this video, if you have any doubt, you can ask me, OK?

260
00:16:42,340 --> 00:16:42,820
Thank you.
