1
00:00:01,320 --> 00:00:01,620
Hello.

2
00:00:01,620 --> 00:00:02,490
Welcome back.

3
00:00:02,490 --> 00:00:06,120
In this lesson we're going to look at loops in Python.

4
00:00:06,120 --> 00:00:08,430
So this our last project or do its names.

5
00:00:08,550 --> 00:00:10,530
It's named conditions and loops.

6
00:00:10,530 --> 00:00:15,780
We didn't explode loops and now so I'm adding this other lesson for us to see loops.

7
00:00:16,200 --> 00:00:18,360
So I'm going to come over here.

8
00:00:18,360 --> 00:00:24,690
New file and I'm going to call this loops by pressing control is to save and I call this number five

9
00:00:24,690 --> 00:00:26,550
on this call loops.

10
00:00:26,550 --> 00:00:29,230
And once that is done I can close this old one.

11
00:00:29,630 --> 00:00:35,280
So python like any other programming language uses the for loop and the while one loop all the while

12
00:00:35,280 --> 00:00:42,090
loop for loops can iterate very a given sequence and this young example we can say this time let's add

13
00:00:42,090 --> 00:00:48,060
some comments to print out these simple examples we shall print in the end so I'll put a header here

14
00:00:48,260 --> 00:00:49,980
I'll put a comment which I'll call.

15
00:00:49,980 --> 00:00:50,790
Example 1

16
00:00:55,310 --> 00:01:01,960
and this example shall we just print one through 8 like this.

17
00:01:02,150 --> 00:01:05,530
Let's just put this here printing simple one resort.

18
00:01:05,660 --> 00:01:09,390
This will make our output much more clearer.

19
00:01:09,410 --> 00:01:11,200
Print example.

20
00:01:11,450 --> 00:01:11,870
Right.

21
00:01:12,140 --> 00:01:14,490
So now let's say we have a list of numbers.

22
00:01:14,510 --> 00:01:17,280
I'm just going to have a variable here numbers.

23
00:01:17,300 --> 00:01:28,970
And this is a list and it's going to be a list contained in 0 1 2 3 4 5 6 7 8.

24
00:01:29,000 --> 00:01:34,400
Like this we've got a call mohair so we have these numbers.

25
00:01:34,530 --> 00:01:39,480
So to look through this list we can just do four.

26
00:01:40,320 --> 00:01:46,130
And then we have to create an iterator we use num here some as an integrator.

27
00:01:46,160 --> 00:01:46,820
What is this.

28
00:01:46,830 --> 00:01:49,770
It's rates are going to loop or look through.

29
00:01:49,770 --> 00:01:53,170
So we're going to say for num in numbers like this.

30
00:01:53,350 --> 00:01:57,760
So we're going to use this iterator to loop through this one here.

31
00:01:57,750 --> 00:02:01,310
Once that is done we can see print.

32
00:02:01,860 --> 00:02:02,220
Now

33
00:02:06,240 --> 00:02:11,880
so this one is going to go through 0 1 2 3 4 5 6 7 8.

34
00:02:11,920 --> 00:02:12,200
OK.

35
00:02:12,240 --> 00:02:13,550
Let's print and see.

36
00:02:13,740 --> 00:02:16,740
I'm just going to click over here to run module.

37
00:02:16,940 --> 00:02:17,380
OK.

38
00:02:17,400 --> 00:02:20,360
To save that I can see.

39
00:02:20,490 --> 00:02:24,330
Example one resorts to a one two three four five six seven eight.

40
00:02:24,560 --> 00:02:25,250
Right.

41
00:02:25,250 --> 00:02:34,070
So with lubed through the sequence very simply also we can use the for loop to iterate or loop through

42
00:02:34,560 --> 00:02:35,720
a range.

43
00:02:35,750 --> 00:02:36,410
Let's what I mean.

44
00:02:36,650 --> 00:02:46,730
So over here I'll just say example to put a comment here for a revision a sample to print the numbers

45
00:02:47,360 --> 00:02:50,600
0 1 2 3 4.

46
00:02:51,380 --> 00:02:53,210
So I can just come in and say print

47
00:03:02,050 --> 00:03:04,400
sample to resorts.

48
00:03:05,320 --> 00:03:05,890
Right.

49
00:03:05,960 --> 00:03:13,410
Let's get to the actual code so we can see for x in range 5.

50
00:03:13,510 --> 00:03:17,470
We can just use the word range here and pass the documents five.

51
00:03:17,650 --> 00:03:23,550
And basically this means from zero through four So five is not included.

52
00:03:23,560 --> 00:03:24,010
Right.

53
00:03:24,100 --> 00:03:30,940
If we say range six six is not included is anything below six range 10 means the same thing zero through

54
00:03:30,940 --> 00:03:35,410
nine range 20 zero through 19.

55
00:03:35,800 --> 00:03:46,110
So for x in range five we can just say we have to put code on here we can just say print x and let's

56
00:03:46,110 --> 00:03:53,130
do that and see what we've got or save by press and control and X and click over here to run the module

57
00:03:54,680 --> 00:04:03,500
you can see we've got serial One two three four right let's see on that example so rather than just

58
00:04:03,500 --> 00:04:10,160
print the range we can actually select certain numbers in the range that should be printed.

59
00:04:10,250 --> 00:04:19,040
Let's see this example just copy this to prevent the typing noise put over here and I'll see.

60
00:04:19,050 --> 00:04:28,380
Example three this time we're going to print Hubble would print 3 4 5 less print 3 4 5

61
00:04:33,410 --> 00:04:38,640
we're going to print from 3 through 5 like this.

62
00:04:38,640 --> 00:04:50,750
So we can just come here and see for x in range this time we'll can pass two argument three comma six

63
00:04:52,080 --> 00:04:52,850
right.

64
00:04:52,950 --> 00:05:05,740
Then we can see we put a semicolon her and then we can see print x let's just spaced this out a bit.

65
00:05:06,290 --> 00:05:13,630
So this is a sample number three resort to our click over here to run hits enter to save.

66
00:05:13,730 --> 00:05:21,530
Now you can see we have 3 4 5 printed here just like we passed over here 3 4 5 and this has got nothing

67
00:05:21,530 --> 00:05:28,940
to do with the list really range just provides the numbers for us so it's print an X in this range three

68
00:05:28,980 --> 00:05:31,160
four five without a six.

69
00:05:31,370 --> 00:05:32,550
Right.

70
00:05:32,570 --> 00:05:35,840
So let's see on that example.

71
00:05:36,240 --> 00:05:38,230
And it doesn't have to be completely sequential.

72
00:05:38,240 --> 00:05:42,520
Sometimes we can jump over sets in numbers in the sequence.

73
00:05:42,540 --> 00:05:50,890
Let's do example for this time we're going to print something like 3 5 7 and we're going to use range

74
00:05:50,890 --> 00:05:52,430
in a different way.

75
00:05:52,450 --> 00:05:53,540
Copy this.

76
00:05:53,800 --> 00:05:54,870
Then I'll bring it down.

77
00:05:54,880 --> 00:05:59,160
This is just to make our printouts look good.

78
00:05:59,560 --> 00:06:10,560
And this one is going to bring 3 5 7 and this is going to be Example number 4.

79
00:06:10,860 --> 00:06:19,770
So to do that we can just come here and see 4 x 4 x in range.

80
00:06:20,160 --> 00:06:22,760
This time we can pass three arguments.

81
00:06:22,800 --> 00:06:28,910
We can pass three eight and then two.

82
00:06:28,980 --> 00:06:34,700
So this is going to be the step size is going to print three and then jump two steps.

83
00:06:34,700 --> 00:06:36,680
Bring the other number in then jump two steps.

84
00:06:36,680 --> 00:06:37,560
Bring the other number.

85
00:06:37,830 --> 00:06:39,420
So we see print within this range.

86
00:06:39,420 --> 00:06:40,770
This is the lower boundary.

87
00:06:40,770 --> 00:06:42,590
This the upper boundary.

88
00:06:42,990 --> 00:06:46,850
And this should be the steps rather than go three four five six seven.

89
00:06:47,010 --> 00:06:52,900
Go three jump two steps which will give us five.

90
00:06:52,920 --> 00:06:57,090
And then when you reach five jump another two steps which would give us seven.

91
00:06:57,090 --> 00:06:57,810
Then you print.

92
00:06:57,810 --> 00:06:58,620
Let's see what I mean.

93
00:06:58,950 --> 00:07:04,300
So I put a semicolon here and then I'll say print x like this.

94
00:07:04,300 --> 00:07:05,730
And this is example for.

95
00:07:05,760 --> 00:07:12,480
So let's observe for example for print control as to save click over here to run the module and we have

96
00:07:12,480 --> 00:07:15,560
three four five three five seven.

97
00:07:15,780 --> 00:07:17,400
Just like we stated here.

98
00:07:17,910 --> 00:07:19,950
So we'll use this as the steps.

99
00:07:19,950 --> 00:07:21,150
This is the range.

100
00:07:21,160 --> 00:07:28,420
Three three through eight and then we use to us this step size right.
