1
00:00:00,870 --> 00:00:05,070
Before we round up the section on loops and flow control,

2
00:00:05,210 --> 00:00:07,250
I want us to take a look at one more

3
00:00:07,260 --> 00:00:11,050
statement and that's going to be the continue statement.

4
00:00:11,380 --> 00:00:15,050
So far we've been working with the break statement and this is of course,

5
00:00:15,060 --> 00:00:19,840
used to end the loop once a particular condition has been met.

6
00:00:20,040 --> 00:00:22,120
But what if for one reason or the other,

7
00:00:22,270 --> 00:00:26,530
we simply wanted to skip a particular iteration or a part of a loop?

8
00:00:26,780 --> 00:00:28,200
We don't want to end the loop

9
00:00:28,670 --> 00:00:31,940
exactly. We just want to skip a particular step.

10
00:00:32,080 --> 00:00:35,659
This is where continue comes into play.

11
00:00:35,669 --> 00:00:38,290
So let me give you an example, let me just remove

12
00:00:38,779 --> 00:00:39,810
this code

13
00:00:40,099 --> 00:00:44,349
and let's say for number in

14
00:00:44,860 --> 00:00:47,619
an hour range, one

15
00:00:47,990 --> 00:00:49,290
comma six.

16
00:00:49,909 --> 00:00:50,529
OK.

17
00:00:50,540 --> 00:00:55,840
Now you're probably wondering what exactly is range range here is simply a,

18
00:00:55,849 --> 00:00:57,409
an inbuilt function

19
00:00:58,090 --> 00:00:59,299
within Python

20
00:00:59,569 --> 00:01:02,669
that will generate numbers between a set in our range.

21
00:01:02,680 --> 00:01:05,750
So in this case, right now, we're saying numbers between one and six.

22
00:01:05,949 --> 00:01:10,269
However, please do keep in mind that when you're working with the range function,

23
00:01:10,760 --> 00:01:12,080
uh the first,

24
00:01:12,279 --> 00:01:15,669
the first number here, which is one will be inclusive

25
00:01:15,959 --> 00:01:17,910
while the last number here is which is six

26
00:01:17,919 --> 00:01:20,819
will not be inclusive inclusive to be exclusive.

27
00:01:20,830 --> 00:01:21,230
So

28
00:01:21,449 --> 00:01:24,669
if I was to simply say, ok, just simply print

29
00:01:25,830 --> 00:01:27,029
and then in brackets,

30
00:01:27,260 --> 00:01:28,730
just print the number

31
00:01:29,290 --> 00:01:35,989
you will see right now that we're gonna get 12345. Ok, so please do keep this in mind.

32
00:01:36,400 --> 00:01:37,050
Now,

33
00:01:37,769 --> 00:01:40,190
the function by default will print 12345, right?

34
00:01:40,199 --> 00:01:43,959
But what if we wanted to skip three in this case? OK. So

35
00:01:44,089 --> 00:01:48,550
we want to forgot to print 124 and then five, right?

36
00:01:48,860 --> 00:01:49,389
So

37
00:01:49,510 --> 00:01:51,069
how are we going to do this?

38
00:01:51,230 --> 00:01:54,720
This is where the continue statement is going to come into play.

39
00:01:54,860 --> 00:01:58,260
But first of all, I need to create the if statement to check

40
00:01:58,809 --> 00:02:00,230
if the number

41
00:02:01,019 --> 00:02:04,319
is equal to three, right?

42
00:02:05,569 --> 00:02:08,880
So now I'm saying, OK, if it's equal to three,

43
00:02:09,070 --> 00:02:10,589
just continue,

44
00:02:11,630 --> 00:02:15,009
I don't need to add the L statement in here because

45
00:02:15,199 --> 00:02:17,919
when you're working with the continue statement, it is understood.

46
00:02:17,929 --> 00:02:19,369
So Python will simply say, OK,

47
00:02:19,880 --> 00:02:22,410
once I get to three, I'm going to skip it out,

48
00:02:22,419 --> 00:02:25,520
I'm gonna skip three and then simply continue with the rest of the loop.

49
00:02:25,529 --> 00:02:31,660
So now if I was to run the program, now you can see it is 124

50
00:02:31,820 --> 00:02:33,369
and then five.

51
00:02:33,580 --> 00:02:38,300
So that's basically how they continue. Our statement would work.

52
00:02:38,369 --> 00:02:41,000
Let me give you another very quick example. What if

53
00:02:41,429 --> 00:02:44,800
I extended the range here from one to let's say 11

54
00:02:44,960 --> 00:02:45,580
OK.

55
00:02:45,910 --> 00:02:49,970
But now we wanted to check for numbers that are even

56
00:02:50,339 --> 00:02:56,690
and then simply keep those even numbers. We only want to print out the odd numbers.

57
00:02:56,949 --> 00:02:59,889
So again, how are we going to do this? Let's first of all, check to see

58
00:03:00,529 --> 00:03:01,149
if it's divisi

59
00:03:01,250 --> 00:03:03,669
divisible by two. I'm going to say percentage and then,

60
00:03:04,529 --> 00:03:05,440
or two

61
00:03:05,800 --> 00:03:06,839
right here

62
00:03:07,139 --> 00:03:09,279
equals to what equals to zero at

63
00:03:09,820 --> 00:03:10,929
my colon.

64
00:03:11,509 --> 00:03:13,929
And now I'm simply going to say just continue

65
00:03:14,289 --> 00:03:15,929
and then print number.

66
00:03:16,380 --> 00:03:21,570
So now if I was to run the program, now you can see it's simply 1357 and nine,

67
00:03:21,869 --> 00:03:26,309
that's how the continue statement actually works.

68
00:03:26,580 --> 00:03:32,020
Let me just spend one minute to talk a little bit further about the range function.

69
00:03:32,029 --> 00:03:33,130
There is one more thing

70
00:03:33,940 --> 00:03:35,559
that you should be aware of.

71
00:03:35,850 --> 00:03:40,910
The thing about the range function is that it can actually accept three values.

72
00:03:41,139 --> 00:03:44,500
So as an example, let me just add my hashtag

73
00:03:44,860 --> 00:03:46,679
so for example, with range,

74
00:03:47,050 --> 00:03:48,800
you can have something like one,

75
00:03:49,460 --> 00:03:50,589
OK? 10

76
00:03:51,000 --> 00:03:51,839
and then two.

77
00:03:52,479 --> 00:03:57,380
OK? So the function, the range function can accept three different parameters.

78
00:03:57,660 --> 00:03:58,179
All right.

79
00:03:58,320 --> 00:04:01,899
So if you wonder, OK, what exactly are these going to be? Well,

80
00:04:02,050 --> 00:04:06,289
the very first number in here will represent the start value, which is one,

81
00:04:06,539 --> 00:04:11,059
the second one here will represent the stop value, which is going to be 10.

82
00:04:11,100 --> 00:04:13,979
While the third value right here will represent two,

83
00:04:14,190 --> 00:04:17,540
which will be the steps that must be skipped.

84
00:04:17,950 --> 00:04:19,980
So by default,

85
00:04:20,660 --> 00:04:23,600
let me just show you how this work right now. If I was to go come over here right now

86
00:04:23,809 --> 00:04:26,000
and then say 110

87
00:04:26,450 --> 00:04:27,359
or two,

88
00:04:27,989 --> 00:04:31,130
just as an example, let me just remove the continue statement in here.

89
00:04:31,989 --> 00:04:32,529
OK?

90
00:04:33,679 --> 00:04:36,660
If I, if I was to go ahead now, right now, I'm printing these numbers,

91
00:04:37,589 --> 00:04:38,700
you will see

92
00:04:38,980 --> 00:04:44,640
that it is now 1357 and nine. Why? Because we are skipping every two,

93
00:04:45,269 --> 00:04:46,290
this step is gonna be two.

94
00:04:46,299 --> 00:04:48,970
So it's gonna go to from one, it's gonna skip to three,

95
00:04:48,980 --> 00:04:50,570
it's gonna skip to five and so on.

96
00:04:50,690 --> 00:04:53,769
If I was to change this one right now to three,

97
00:04:54,130 --> 00:04:56,070
can you guess what the values are going to be?

98
00:04:56,339 --> 00:05:00,850
Now? It's going to be 147.

99
00:05:01,589 --> 00:05:02,850
So if I run the program,

100
00:05:03,160 --> 00:05:06,369
there you go 147.

101
00:05:06,670 --> 00:05:09,790
So you may or may not work with the range function in the future.

102
00:05:09,799 --> 00:05:12,679
But I just feel it's important for you to at least understand

103
00:05:12,959 --> 00:05:16,920
is that the range function can accept up to three different parameters.

104
00:05:17,079 --> 00:05:21,600
The first value in here being the start, second being the stop number. And then the

105
00:05:21,940 --> 00:05:25,720
uh last valuing had been the step number. And keep in mind

106
00:05:25,859 --> 00:05:28,679
that the stop value is always exclusive.

107
00:05:28,890 --> 00:05:31,399
It's not going to be included in the

108
00:05:31,410 --> 00:05:35,059
actual results of that particular range function.

109
00:05:35,630 --> 00:05:37,959
Final thing to mention, final thing to mention,

110
00:05:38,820 --> 00:05:44,720
you may also come across a particular statement called the pass statement.

111
00:05:45,670 --> 00:05:47,109
It just goes like this, right?

112
00:05:47,119 --> 00:05:49,850
You you sort of continue, for example, you will see a pass,

113
00:05:49,970 --> 00:05:50,470
right

114
00:05:50,769 --> 00:05:52,720
pass doesn't really do anything.

115
00:05:53,239 --> 00:05:54,160
Honestly,

116
00:05:54,970 --> 00:06:00,029
it's really used for passing comments. Maybe the

117
00:06:00,239 --> 00:06:03,470
developer of the program doesn't want to execute something

118
00:06:03,480 --> 00:06:05,269
yet but wants to leave like a note.

119
00:06:05,540 --> 00:06:08,809
That's what the past statement is mostly used for.

120
00:06:08,929 --> 00:06:11,019
We're not going to be working with it at all.

121
00:06:11,660 --> 00:06:14,959
So for example, in here, I could say something like OK pass and then

122
00:06:15,160 --> 00:06:16,640
I can add my hashtag

123
00:06:16,779 --> 00:06:19,720
and I can say I will add the function

124
00:06:20,220 --> 00:06:21,579
uh later.

125
00:06:21,850 --> 00:06:24,260
OK? Just as an example, right? So let me just

126
00:06:24,440 --> 00:06:25,339
go ahead

127
00:06:25,660 --> 00:06:27,410
and run the program

128
00:06:27,579 --> 00:06:30,649
and you can see right now the program still works. Uh anyway, right?

129
00:06:30,660 --> 00:06:31,920
So it's not, it's not gonna,

130
00:06:32,420 --> 00:06:36,109
it doesn't really do anything as such. So

131
00:06:36,820 --> 00:06:39,040
uh that's pretty much it.

132
00:06:39,260 --> 00:06:40,359
Thank you for watching the video.

133
00:06:40,480 --> 00:06:42,200
I will see you in the next class.

