1
00:00:00,480 --> 00:00:06,840
A for loop allows us to execute a block of code repeatedly they come in handy if you want the same code

2
00:00:06,870 --> 00:00:10,660
to run over and over again each time with a different value.

3
00:00:11,890 --> 00:00:16,540
Let's take a look at an example to illustrate how for loops work.

4
00:00:16,740 --> 00:00:23,580
The objective of the for loop we create will be to output the values zero to 10 on separate lines in

5
00:00:23,580 --> 00:00:26,190
our HMO document as shown here

6
00:00:30,100 --> 00:00:38,280
so let's go ahead and get started.

7
00:00:38,330 --> 00:00:43,370
The first thing we need to do is declare the variable that will contain our initial values

8
00:00:47,000 --> 00:00:52,070
we'll call this variable count.

9
00:00:52,080 --> 00:00:57,090
Now we can create our for loop to do so type the following block of code

10
00:01:10,110 --> 00:01:10,890
and that's it.

11
00:01:11,010 --> 00:01:15,830
In this block of code we first established the for loop.

12
00:01:15,900 --> 00:01:19,330
Next we define the parameters of the for loop.

13
00:01:19,440 --> 00:01:24,410
We've set the initial value for variable count to 0.

14
00:01:24,420 --> 00:01:32,440
We then instruct the script that the value should increment by 1 up to a maximum of 10 the document

15
00:01:32,440 --> 00:01:41,510
dot write functions simply output each value in the loop separated by a line break.

16
00:01:41,600 --> 00:01:50,070
So let's go ahead and save this file and tested in our web browser to make sure it works and we can

17
00:01:50,070 --> 00:01:59,320
see here that each value is output it onto a separate line just as we instructed it to do.

18
00:01:59,340 --> 00:02:05,370
Now let's see what would happen if we were to change the value of our account variable to a different

19
00:02:05,580 --> 00:02:07,170
value.

20
00:02:07,170 --> 00:02:13,530
I'll change it to 3 save the file and refresh.

21
00:02:13,560 --> 00:02:17,910
Now we can see that our initial value starts at 3 and increments up to 10

22
00:02:24,510 --> 00:02:29,710
we can increase our maximum value by changing 10 to 20 for example.

23
00:02:33,190 --> 00:02:37,650
And now it'll keep looping until it reaches 20 instead of 10.
