1

00:00:01,030  -->  00:00:06,910
Not let's look at a very commonly used Concord for a statement called for a statement or follow up.

2

00:00:07,110  -->  00:00:14,400
So it has something to do with looping a fun loop is typically used to iterate or loop over elements

3

00:00:14,400  -->  00:00:20,340
of an array or a similar data structure and do something with each element like printing what the element

4

00:00:20,340  -->  00:00:21,610
is.

5

00:00:21,630  -->  00:00:26,780
For example when we visit e-commerce websites Visi products displayed as a list.

6

00:00:27,180  -->  00:00:29,500
This is usually done with a follow up.

7

00:00:29,580  -->  00:00:34,530
That is the products would be stored in some kind of a data structure like an IRA under for a loop.

8

00:00:34,580  -->  00:00:40,670
What they don't want the array to display each part product stored in the art that is in each iteration

9

00:00:40,860  -->  00:00:44,280
data associated with one product is displayed.

10

00:00:44,280  -->  00:00:46,930
Let's see how a for loop accomplishes something like this.

11

00:00:48,610  -->  00:00:51,080
Follow up is basically an iteration statement.

12

00:00:51,980  -->  00:00:56,820
Need it you know it's our executive block of code for some number of things.

13

00:00:57,080  -->  00:01:01,010
How many times a block of code is executed is dependent on some condition.

14

00:01:02,840  -->  00:01:06,060
I think the best way to understand follow is to be a simple example.

15

00:01:06,080  -->  00:01:13,360
And here we have one here you have an idea containing an immense Indigos zero to nine under statement

16

00:01:13,600  -->  00:01:21,010
simply because there are elements so the statement includes the key word for followed by parenthesis

17

00:01:21,550  -->  00:01:27,730
which includes a few xperience that and this is followed by the body of follow up riches and President

18

00:01:27,730  -->  00:01:35,050
quali basis know within the band this is we have three expressions separated by semi-colons and these

19

00:01:35,050  -->  00:01:42,220
two semi-colons are mandatory the first expulsion is basically an initialization expression and it is

20

00:01:42,220  -->  00:01:44,580
initializing the variable to zero.

21

00:01:45,390  -->  00:01:52,900
I is basically used as a risk index number also since I is being declared here it is visible only within

22

00:01:52,900  -->  00:01:59,360
the first statement that is it is accessible outside of the for statement the second expression is a

23

00:01:59,360  -->  00:02:05,190
condition and it is what decides whether the body or for statement should be executed or not.

24

00:02:05,660  -->  00:02:12,810
So during the first iteration the condition would be zero less than 10 done is the size of the third

25

00:02:12,810  -->  00:02:19,500
expression is simply an increment operation which helps and it did it in the ADI So those are different

26

00:02:19,500  -->  00:02:21,790
expressions within the patent cases.

27

00:02:21,810  -->  00:02:28,210
Now let's look at the concurrent fruits and so initially in the first iteration the variable I would

28

00:02:28,210  -->  00:02:29,560
be initialized to zero.

29

00:02:30,510  -->  00:02:37,190
And then next up condition is checked that is whether I is less than 10 is true or false since I have

30

00:02:37,190  -->  00:02:39,560
zero and zero is less than 10.

31

00:02:39,590  -->  00:02:41,660
The body of first statement is executed.

32

00:02:41,760  -->  00:02:44,510
So the first element of the array gets printed.

33

00:02:45,020  -->  00:02:51,240
Next I will be incremented to one due to the increment expression end up a nation will be checked once

34

00:02:51,240  -->  00:02:52,020
again.

35

00:02:52,640  -->  00:02:56,960
Distend the condition will be run less than 10 which is also true.

36

00:02:56,990  -->  00:03:02,090
And so the body of false statement gets executed again and this time the first element of the array

37

00:03:02,180  -->  00:03:09,150
would be printed next I would be incremented to after it is a condition Bulla's then is ject.

38

00:03:09,670  -->  00:03:15,100
So the cycle of checking the condition excluding the body or first statement and then doing the increment

39

00:03:15,100  -->  00:03:21,510
operation continues until I become certain at which point the condition fails as done unless less intent

40

00:03:21,570  -->  00:03:22,500
would be false.

41

00:03:23,330  -->  00:03:28,240
So at this point the fun look for the exit under statement following the for loop would be exaggerated

42

00:03:28,260  -->  00:03:28,450
.

43

00:03:29,580  -->  00:03:33,200
So the initialization expression is executed only once.

44

00:03:33,360  -->  00:03:39,290
But the other two expressions on the body are for a loop are executed multiple times at the end of the

45

00:03:39,290  -->  00:03:44,480
lesson Wyburn exhibit the simple example and we will also try on some of the stuff that we are going

46

00:03:44,480  -->  00:03:52,440
to see in this lesson here is a general form of a statement like we discussed the parenthesis includes

47

00:03:52,530  -->  00:03:58,770
three parts initialization condition expression and the exhibitionist expressionless part is the part

48

00:03:58,860  -->  00:04:02,950
that usually does the increment or sometimes even decrement operation.

49

00:04:05,090  -->  00:04:11,320
Here in addition Parker can be either a variable declaration statement or it can be a list of common

50

00:04:11,320  -->  00:04:18,190
separated expression statements if you recall a statement can be of three types declaration expression

51

00:04:18,250  -->  00:04:25,860
or a control flow statement is the expression this part can also have a list of comma separated expressions

52

00:04:25,860  -->  00:04:32,790
statements but it cannot have any declarations statements condition expression will always be some kind

53

00:04:32,790  -->  00:04:39,530
of a boolean expression not just look at each of these parts up lately although for the sake of completeness

54

00:04:39,760  -->  00:04:43,900
we will look at several different ways in which four statements can be written.

55

00:04:43,910  -->  00:04:48,320
Typically you would not write for loops that are different from the example we saw earlier.

56

00:04:50,140  -->  00:04:52,690
So let's begin with the initialization part.

57

00:04:52,710  -->  00:04:55,470
The initialization part is optional.

58

00:04:56,000  -->  00:04:59,560
And the example we just saw can also be rewritten as shown here.

59

00:05:00,530  -->  00:05:06,320
Hear the index variable initialization is done outside of outlook on the initialization part of the

60

00:05:06,320  -->  00:05:07,660
for loop is empty.

61

00:05:09,800  -->  00:05:15,040
Initialization part can have a single declaration statement on this is the most common scenario.

62

00:05:16,600  -->  00:05:18,480
On Here are a few examples.

63

00:05:18,570  -->  00:05:20,170
First example is straightforward.

64

00:05:20,340  -->  00:05:26,560
On something we have already seen second example is declaring variables and we know that it is a valid

65

00:05:26,560  -->  00:05:32,420
declaration statement third and fourth examples are invalid third is invalid.

66

00:05:32,600  -->  00:05:39,570
Even the board wearables are same type so you can only have one declare Mission Statement in the initialization

67

00:05:39,570  -->  00:05:40,070
part.

68

00:05:41,030  -->  00:05:47,030
Note that these last two examples are invalid even if those statements appeared independently outside

69

00:05:47,030  -->  00:05:48,380
of a statement.

70

00:05:48,890  -->  00:05:54,830
So basically what we are seeing here are proper declarations statements and if they are invalid outside

71

00:05:54,830  -->  00:05:59,480
of her statement then they are invalid even when used within the first statement.

72

00:06:01,400  -->  00:06:07,360
Initialization but can also how a list of explicit statements that are called Must up later on let's

73

00:06:07,370  -->  00:06:08,650
look at few examples.

74

00:06:10,650  -->  00:06:17,160
Here in the first example the variables i and j are being re-initialize that is they're already declared

75

00:06:17,220  -->  00:06:20,660
outside of Outlook and they are simply being reinitialized here.

76

00:06:21,580  -->  00:06:28,670
Second example shows that you cannot mix an expression statement with their declaration statement next

77

00:06:28,670  -->  00:06:33,110
we can have all of these expressions statements and they are all valid.

78

00:06:33,110  -->  00:06:39,080
And I would say you should avoid using initialization part and this bit as I'm sure many birds are not

79

00:06:39,080  -->  00:06:44,420
even aware of such a possibility and hence the code would be very confusing.

80

00:06:44,420  -->  00:06:52,670
So use any or they can but for either variable declaration or variable re initialization next is condition

81

00:06:52,670  -->  00:06:59,190
exhibition on Binoy it must evaluate the boolean value it can also be optional.

82

00:06:59,340  -->  00:07:05,190
And so if omitted it Drew would be as you were and we may end up with an infinite loop.

83

00:07:06,810  -->  00:07:08,390
And here is an example.

84

00:07:08,860  -->  00:07:14,970
No one didn't find a group that can use a break statement like in the case of switch statement using

85

00:07:14,970  -->  00:07:17,630
break statements with followups will be discussed later.

86

00:07:19,620  -->  00:07:25,230
Find them if you have the experience part they can also have a list of call most x Mission Statements

87

00:07:25,680  -->  00:07:29,510
like in the case of initialization part.

88

00:07:29,680  -->  00:07:35,200
And here is one example which has been just rewritten here the print statement has been moved into the

89

00:07:35,290  -->  00:07:42,130
expressionless part which also includes the increment operation not the semicolon is required at the

90

00:07:42,130  -->  00:07:48,450
end of her statement as there is no explicit body we can also take this one step further and make it

91

00:07:48,480  -->  00:07:49,670
even more compact.

92

00:07:50,920  -->  00:07:56,690
Unheeded is here the inexplainable is incremented within the print statement itself.

93

00:07:57,870  -->  00:07:59,280
All we can write our statements.

94

00:07:59,280  -->  00:08:04,500
This meant Typically you would have only an increment or decrement operation in the expression of the

95

00:08:04,500  -->  00:08:05,100
spark.

96

00:08:06,030  -->  00:08:07,490
So that's a fair statement.

97

00:08:07,670  -->  00:08:12,660
No let's go ahead and Bouchard them all of some of the stuff we have learned in this lesson.

98

00:08:14,570  -->  00:08:18,320
In the interest of time I'm going to show this to mind my Eclipse ID.

99

00:08:18,590  -->  00:08:21,670
And here we are in the basic class within domain.

100

00:08:22,070  -->  00:08:27,140
And this is the same example that we have seen earlier where we are printing the elements from zero

101

00:08:27,140  -->  00:08:27,940
to nine.

102

00:08:28,280  -->  00:08:29,820
So let's just go ahead and run this.

103

00:08:29,840  -->  00:08:31,190
Just click this button here.

104

00:08:31,550  -->  00:08:34,830
And as you can see all the elements of getting printed here.

105

00:08:34,990  -->  00:08:35,740
OK.

106

00:08:35,820  -->  00:08:39,450
And so this is the most typical way in which you would use a follow up.

107

00:08:39,590  -->  00:08:40,000
OK.

108

00:08:40,190  -->  00:08:45,320
But we have also seen different reason which could be used different Boehmer additions and combinations

109

00:08:45,360  -->  00:08:45,950
.

110

00:08:45,970  -->  00:08:52,530
And you look at some off them so one of them was that the initialization part can be optional.

111

00:08:54,180  -->  00:08:57,020
So the declaration can be done outside of loop.

112

00:08:57,190  -->  00:09:02,930
So it should give us the same result and you can see that we have the same result here.

113

00:09:02,950  -->  00:09:11,930
So let me just move it back now we also said that we cannot have this kind of declaration.

114

00:09:11,940  -->  00:09:15,300
So it is invalid and it giving it completion.

115

00:09:15,360  -->  00:09:17,480
So you can see that red line here.

116

00:09:17,580  -->  00:09:19,560
So the right re is.

117

00:09:19,580  -->  00:09:21,900
So this is the right way off declaring it.

118

00:09:22,260  -->  00:09:22,900
OK.

119

00:09:23,280  -->  00:09:25,370
So this is still a declaration statement.

120

00:09:25,380  -->  00:09:30,970
Now we said that we can that initial edition but and also how ex-Special statements.

121

00:09:31,120  -->  00:09:34,840
So so this is a declaration.

122

00:09:34,880  -->  00:09:41,190
And here we can re-initialize them do i equal to one.

123

00:09:41,190  -->  00:09:47,650
And Jake will do one not this would only print the elements 1 2 9.

124

00:09:47,750  -->  00:09:48,050
OK.

125

00:09:48,070  -->  00:09:51,540
So we how IAG is not being used anywhere.

126

00:09:51,540  -->  00:09:59,880
So in this case you can see that it's printing 8:59 now other than that we also can how expression statements

127

00:09:59,880  -->  00:10:11,240
over here multiple exhibitions statements in the exhibition list and that's also put I lay off de Let's

128

00:10:11,390  -->  00:10:20,860
put an empty string here Mr. double caught quote then whitespace let me just make it g.

129

00:10:21,270  -->  00:10:23,300
So you also how I and J now.

130

00:10:23,510  -->  00:10:25,820
And let's also put another condition here.

131

00:10:29,260  -->  00:10:35,830
Get less than I read out and so that's the whole condition expression and we are incrementing both I

132

00:10:35,830  -->  00:10:36,610
and J here.

133

00:10:36,670  -->  00:10:38,940
So let's just run this.

134

00:10:39,010  -->  00:10:45,130
So now it's blending dot elements and this bit I read off by an idea off just so it will just be the

135

00:10:45,130  -->  00:10:46,750
same element.

136

00:10:46,920  -->  00:10:52,560
Now let's just go back let's make it I equals zero.

137

00:10:52,560  -->  00:10:53,760
Let me also remove this

138

00:11:02,820  -->  00:11:07,950
and if you recall the last example was moving this here

139

00:11:10,650  -->  00:11:15,470
and making this plus plus unlimited modus

140

00:11:19,980  -->  00:11:22,170
So the opening statement has been moved here.

141

00:11:22,300  -->  00:11:27,550
But as you can see it gives a compiler because there is nobody and said that we need a semicolon here

142

00:11:27,560  -->  00:11:27,840
.

143

00:11:28,060  -->  00:11:29,910
Now it's right.

144

00:11:29,920  -->  00:11:35,550
So this is the most compact form on if you add on it it prints all done in advance.

145

00:11:35,560  -->  00:11:37,640
So that was the last one which we have seen.

146

00:11:37,930  -->  00:11:39,910
So that's a lot for loop.

147

00:11:40,330  -->  00:11:46,420
And next we will look at something called and hands for loop and also in the seamless entry would also

148

00:11:46,420  -->  00:11:49,890
look at a commendation from effective July item.

149

00:11:49,930  -->  00:11:52,410
Ok then go ahead and try this out.

150

00:11:52,410  -->  00:11:54,750
Play with it and that's it.

151

00:11:54,760  -->  00:11:55,860
Happy coding ironed.

152

00:11:55,870  -->  00:11:56,260
Thank you
