Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,270 --> 00:00:05,790
Well, hello there, ladies and gentlemen, and welcome back to our Alphatech Academy program in Chorus.
2
00:00:06,120 --> 00:00:07,600
My name is tech teacher Vlad.
3
00:00:07,830 --> 00:00:13,960
And in this video, in this lesson, we're going to talk about a looping control structure called Ferral
4
00:00:13,960 --> 00:00:15,450
Loops so we can save it.
5
00:00:15,450 --> 00:00:22,980
A for a loop is also a loop, and it's simply used to execute some commands at the loop body over and
6
00:00:22,980 --> 00:00:23,730
over again.
7
00:00:23,850 --> 00:00:26,910
As long as the loop condition is satisfied.
8
00:00:27,030 --> 00:00:30,880
This type of loop is also sometimes called a counting loop.
9
00:00:31,200 --> 00:00:33,780
And we will see why right away.
10
00:00:33,930 --> 00:00:40,770
If we compare it to, let's say, the while loop, we can say that while loop only contains a condition,
11
00:00:40,950 --> 00:00:45,530
but the for a loop will be slightly off a different structure.
12
00:00:45,580 --> 00:00:48,540
Okay, so the for a loop looks like this.
13
00:00:48,630 --> 00:00:55,400
First of all, like with the wire loops, you first use the statement for two star there for a loop.
14
00:00:55,410 --> 00:00:59,310
You specify that we are that you are working with a for loop.
15
00:00:59,850 --> 00:01:08,010
Second, there are going to be three very important sections that are used to construct the for itself,
16
00:01:08,280 --> 00:01:09,720
the force structure itself.
17
00:01:09,870 --> 00:01:16,230
The first one is the initialization statement, which will be executed just once.
18
00:01:16,380 --> 00:01:23,310
Please note it will be executed just once and it will be when we encounter the for loop for the first
19
00:01:23,310 --> 00:01:23,730
time.
20
00:01:23,940 --> 00:01:26,970
It's sort of the starting point of the loop.
21
00:01:27,300 --> 00:01:27,740
Okay.
22
00:01:27,800 --> 00:01:30,240
It's just the first time you admitted you executed.
23
00:01:30,750 --> 00:01:36,420
Sometimes it's even called the variables initialization phase, and that is you.
24
00:01:36,650 --> 00:01:45,810
It is being used for the initialization of variables which are going to take a major path in this loop
25
00:01:45,810 --> 00:01:46,740
functionality.
26
00:01:46,770 --> 00:01:52,560
You will see exactly why we are creating an initializing these variables.
27
00:01:52,680 --> 00:01:55,950
So the second section is actually the loop condition.
28
00:01:56,130 --> 00:02:00,930
The second section is going to be the loop condition, just like the loop condition we've seen in the
29
00:02:00,930 --> 00:02:01,620
while loop.
30
00:02:01,650 --> 00:02:02,550
Nothing special.
31
00:02:02,570 --> 00:02:07,140
It's just a condition that may be either a true or false.
32
00:02:07,260 --> 00:02:13,320
And as long as these specified condition is not false, meaning it's true, as long as these condition
33
00:02:13,350 --> 00:02:19,320
as the loop condition happens to be true, we are going to execute the body of the loop over and over
34
00:02:19,320 --> 00:02:19,710
again.
35
00:02:19,860 --> 00:02:24,660
And at the end of every duration, we are going to have the update statement.
36
00:02:24,960 --> 00:02:28,170
So lastly, we have this update statement.
37
00:02:28,290 --> 00:02:34,230
And this particular piece of code in the subject statement will be executed at the end.
38
00:02:34,850 --> 00:02:41,340
I mean, whenever we finish a given iteration at the end of every iteration, we are going to execute
39
00:02:41,640 --> 00:02:43,160
these updates statement.
40
00:02:43,490 --> 00:02:47,790
There are going to be a couple of commands, maybe one, maybe non, maybe two.
41
00:02:48,450 --> 00:02:55,080
And they are going to be executed after after we have finished a given iteration.
42
00:02:55,110 --> 00:02:57,120
So at the end of every iteration.
43
00:02:57,270 --> 00:03:04,140
So once a given iteration is over, you go to this section for this updates statement and you run its
44
00:03:04,200 --> 00:03:06,770
updates and go checking me out of the loop.
45
00:03:06,780 --> 00:03:09,420
Condition has been changed.
46
00:03:09,960 --> 00:03:12,280
Now it's maybe either a true or false.
47
00:03:12,420 --> 00:03:13,740
Based on the update.
48
00:03:14,430 --> 00:03:15,600
You've done so far.
49
00:03:16,170 --> 00:03:18,700
And if it's false, you are going to execute two.
50
00:03:18,700 --> 00:03:23,550
Or if it's true, you're going to, of course, run the loop body once again.
51
00:03:24,300 --> 00:03:29,820
Now, before we jumping to coding and see how it works in our programming language, I want us to take
52
00:03:29,820 --> 00:03:38,790
another look at a general explanation, a general visualization of the four of the four loops and why
53
00:03:38,880 --> 00:03:40,500
and how it's being used.
54
00:03:40,590 --> 00:03:43,860
Some some example that I think can be nice for you guys.
55
00:03:43,930 --> 00:03:50,220
Okay, so we have a program with a bunch of commands and we come to a point where we see the forest
56
00:03:50,220 --> 00:03:51,840
statement for the first time.
57
00:03:51,960 --> 00:03:58,440
And that basically means that now we know that we are going to deal with a for loop.
58
00:03:58,560 --> 00:04:05,190
So if we need to deal with a for loop, we first of all, the first thing that we do is we are going
59
00:04:05,190 --> 00:04:11,040
to run the first section that we've previously discussed, the loop initialization step.
60
00:04:11,580 --> 00:04:15,360
So we execute the commands specified in this section just once.
61
00:04:15,490 --> 00:04:15,870
All right.
62
00:04:15,900 --> 00:04:21,770
So in these looping stylization, there are going to be a couple of sections.
63
00:04:21,780 --> 00:04:23,760
And the first one is the initialization.
64
00:04:23,970 --> 00:04:28,980
And in this example, we can say that this first step is executed just once.
65
00:04:29,070 --> 00:04:36,730
So let's assume that it's kind of the fact that Mike's mike arrives to work, OK?
66
00:04:36,810 --> 00:04:39,160
It's just executed once and now.
67
00:04:39,300 --> 00:04:46,290
And now, once Mike arrived to work, we can check if the loop condition, for example, his task,
68
00:04:46,320 --> 00:04:49,410
Mike's task is to do some work.
69
00:04:49,440 --> 00:04:51,660
Let's say, for three hours straight.
70
00:04:51,930 --> 00:04:55,560
And that's the condition if these work has been done.
71
00:04:55,710 --> 00:04:59,730
So we are going to check if this condition is true or false.
72
00:05:00,030 --> 00:05:07,110
And if this condition is satisfied, we are going to execute the loop body once we are executing the
73
00:05:07,110 --> 00:05:08,280
loop body we have.
74
00:05:08,430 --> 00:05:11,700
We can say that we have completed an iteration.
75
00:05:11,700 --> 00:05:12,990
You remember that, right?
76
00:05:13,080 --> 00:05:19,650
So in the loop body, the Labadee execution consists of, let's say Mike has to think what to do and
77
00:05:19,680 --> 00:05:22,680
to code something and then to fix some bugs.
78
00:05:22,710 --> 00:05:22,950
Right.
79
00:05:23,220 --> 00:05:26,010
This is just a one iteration.
80
00:05:26,030 --> 00:05:26,640
He does.
81
00:05:26,880 --> 00:05:36,030
He's three hours straight work in a couple of iteration and in four loops once some iteration is complete.
82
00:05:36,060 --> 00:05:40,110
We should go to the update section and execute the commands specify.
83
00:05:40,190 --> 00:05:45,900
There you can see the commands in this section as commands that are used for preparation for the next
84
00:05:45,900 --> 00:05:46,530
iteration.
85
00:05:46,560 --> 00:05:47,010
All right.
86
00:05:47,160 --> 00:05:49,050
Just look at it this way.
87
00:05:49,140 --> 00:05:55,250
So now you will remember that you have to execute them every time after a certain iteration is completed.
88
00:05:55,260 --> 00:05:56,350
For example, every two.
89
00:05:56,430 --> 00:06:01,370
After every iteration, Mike is going to get something to drink.
90
00:06:01,380 --> 00:06:01,790
I don't know.
91
00:06:01,900 --> 00:06:03,740
That's that's the update statement.
92
00:06:03,780 --> 00:06:09,900
And also, he will mark that he finished one hour of working.
93
00:06:10,020 --> 00:06:16,170
And now once you're done with the update section, you check out the loop condition once again and execute
94
00:06:16,170 --> 00:06:18,240
the loop body based on its result.
95
00:06:18,600 --> 00:06:26,310
And basically, you go over these steps over and over again until the condition will be false or until
96
00:06:26,310 --> 00:06:29,760
you will have some breaking command that makes you out of the loop.
97
00:06:29,880 --> 00:06:33,960
That's something that we are also going to discuss in the next videos.
98
00:06:34,120 --> 00:06:40,830
But I think you've got the point of how for loops work, you initialize, you check a condition, you
99
00:06:40,830 --> 00:06:47,370
run the loop body, and then you prepare for the next iteration by running some update commands.
100
00:06:47,490 --> 00:06:52,530
And once you do so, if you do so correctly, your four loops are ready to go.
101
00:06:53,010 --> 00:06:59,640
So now let's take a look at how it can be used in our programming language and also understand when
102
00:06:59,640 --> 00:07:04,260
using the four loops is preferred over using while loops.
103
00:07:04,410 --> 00:07:07,540
I hope you're ready, guys, and I'll see in the next video.
10063
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.