Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
0
1
00:00:01,690 --> 00:00:09,140
So you learn that a for loop iterate through a container which could be a list, or a string, or a tuple.
1
2
00:00:09,250 --> 00:00:14,140
And the loop will terminate when the container is exhausted.
2
3
00:00:14,140 --> 00:00:19,610
So for example it prints out one, two, and three.
And when there are no more items
3
4
00:00:19,630 --> 00:00:20,850
the loop ends.
4
5
00:00:21,370 --> 00:00:32,950
So a full loop runs until a container is exhausted and a while loop a while loop runs as long as this
5
6
00:00:32,950 --> 00:00:34,030
condition is true.
6
7
00:00:38,330 --> 00:00:42,470
Let me execute that and see what is going to happen.
7
8
00:00:42,470 --> 00:00:49,760
So you will see that 1 is being printed out all the time.
8
9
00:00:49,940 --> 00:00:56,210
So if I scroll up here I will not be able to find where the starting point was because there's a million
9
10
00:00:56,210 --> 00:01:00,550
ones now being printed out there every split of a second.
10
11
00:01:00,590 --> 00:01:09,260
So what's going on here is that a while loop, while is a keyword, and then that is followed by a condition.
11
12
00:01:09,290 --> 00:01:13,820
In this case the condition is that A is greater than zero which is true.
12
13
00:01:13,970 --> 00:01:15,520
So A is actually 3.
13
14
00:01:15,560 --> 00:01:17,450
That means this condition is true.
14
15
00:01:18,050 --> 00:01:27,060
And as long as this condition is true, this will be printed out, so under the while loop you can have
15
16
00:01:27,120 --> 00:01:30,630
as many actions operations as you want.
16
17
00:01:30,630 --> 00:01:35,170
For example let me interrupt this with control C on your terminal.
17
18
00:01:35,720 --> 00:01:41,250
And then add another line here print2, save, execute.
18
19
00:01:41,280 --> 00:01:43,070
So 1 2, 1 2, 1 2, 1 2, 1 2
19
20
00:01:43,170 --> 00:01:44,240
is being printed out.
20
21
00:01:45,850 --> 00:01:47,920
Okay I'll interrupt that.
21
22
00:01:48,080 --> 00:01:51,180
Not the rate that these numbers are being printed out
22
23
00:01:51,190 --> 00:01:52,980
depends on your computer.
23
24
00:01:52,980 --> 00:01:54,100
Processor speed.
24
25
00:01:54,640 --> 00:01:58,740
So the faster your processor, the faster you will get these action here,
25
26
00:01:58,740 --> 00:02:01,540
these operations being executed.
26
27
00:02:01,630 --> 00:02:09,520
Now of course this will always forever be true because it's a just a static declaration of a variable
27
28
00:02:09,520 --> 00:02:10,090
here.
28
29
00:02:10,090 --> 00:02:15,570
So no one is changing it here, therefore of a condition will always be true.
29
30
00:02:15,610 --> 00:02:21,710
You can see inside Python when you check something like 3 is greater than 0 you get true.
30
31
00:02:21,730 --> 00:02:28,110
So this is basically while True, and you will sometimes see it like that.
31
32
00:02:28,110 --> 00:02:29,860
So just delete the first line.
32
33
00:02:33,040 --> 00:02:35,360
Exit here, execute the code again.
33
34
00:02:36,500 --> 00:02:40,140
So again the same thing happens because true is always true.
34
35
00:02:41,900 --> 00:02:46,020
However, this is not how while loops are used in real world.
35
36
00:02:46,250 --> 00:02:50,990
It's meaningless to check if true is true and print out something all the time.
36
37
00:02:51,590 --> 00:02:55,570
So let me go ahead and explain while loops in a better example in the next video.
3669
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.