1
00:00:00,570 --> 00:00:01,740
Narrator: Welcome back.

2
00:00:01,740 --> 00:00:05,130
Now, up until now, we saw the 'break' keyword

3
00:00:05,130 --> 00:00:07,980
that we can use to break out of a loop.

4
00:00:07,980 --> 00:00:10,890
And you see here that we're able to loop with a 'for' loop.

5
00:00:10,890 --> 00:00:14,190
But, with a 'while' loop, as soon as we break, we're done.

6
00:00:14,190 --> 00:00:17,760
We've just, well, broken out of the loop.

7
00:00:17,760 --> 00:00:21,300
But could we do that in a 'for' loop?

8
00:00:21,300 --> 00:00:22,133
Let's find out.

9
00:00:24,270 --> 00:00:28,773
Yep, break keyword, works in a for loop as well.

10
00:00:29,790 --> 00:00:32,940
But, there's actually two other things that

11
00:00:32,940 --> 00:00:36,630
we can use besides 'break'.

12
00:00:36,630 --> 00:00:39,990
One is called 'continue',

13
00:00:39,990 --> 00:00:44,040
and you can see here again, blue highlighting.

14
00:00:44,040 --> 00:00:48,613
If I do 'continue' here, and I click 'run'...

15
00:00:50,010 --> 00:00:50,843
There you go.

16
00:00:50,843 --> 00:00:52,680
We get our looping again.

17
00:00:52,680 --> 00:00:56,580
But, you're thinking, "Why do we need this?"

18
00:00:56,580 --> 00:00:59,730
Like, it seems completely useless, right?

19
00:00:59,730 --> 00:01:03,030
Well, a break, when we use the 'break' statement,

20
00:01:03,030 --> 00:01:06,870
it breaks out of the current and closing loop.

21
00:01:06,870 --> 00:01:09,450
So when we used a 'break' statement,

22
00:01:09,450 --> 00:01:12,480
we broke out of this loop, right?

23
00:01:12,480 --> 00:01:15,360
This whole 'while' loop, we just exited it.

24
00:01:15,360 --> 00:01:18,720
And same with the 'for' loop, we completely exited it.

25
00:01:18,720 --> 00:01:21,847
However, with a 'continue', what we're saying is,

26
00:01:21,847 --> 00:01:25,050
"Hey, whatever happens when you hit this line,

27
00:01:25,050 --> 00:01:28,980
continue onto the top of the enclosing loop."

28
00:01:28,980 --> 00:01:31,110
So the current and closing loop, what is it?

29
00:01:31,110 --> 00:01:32,340
It's this 'for' loop.

30
00:01:32,340 --> 00:01:35,640
So it's going to go back to the for loop.

31
00:01:35,640 --> 00:01:38,343
So that, if I do something like 'print' here,

32
00:01:39,900 --> 00:01:42,420
so that we get it printed twice, or you know what,

33
00:01:42,420 --> 00:01:44,127
let's just move 'print',

34
00:01:45,660 --> 00:01:46,820
down here...

35
00:01:48,780 --> 00:01:50,310
Like that.

36
00:01:50,310 --> 00:01:51,630
And then same here,

37
00:01:51,630 --> 00:01:56,520
we're going to just 'print' at the bottom, after continue.

38
00:01:56,520 --> 00:02:00,510
If I click 'run', nothing gets printed.

39
00:02:00,510 --> 00:02:03,397
Because as soon as it sees continue, it's going to say

40
00:02:03,397 --> 00:02:06,000
"Okay, I'm going to go back to the loop"

41
00:02:06,000 --> 00:02:07,560
and it's going to keep going, keep going,

42
00:02:07,560 --> 00:02:10,350
keep going, until, well, the loop ends.

43
00:02:10,350 --> 00:02:14,283
So that we never actually hit line 10 and line four.

44
00:02:15,360 --> 00:02:19,740
So that becomes really useful in conditional logic as well.

45
00:02:19,740 --> 00:02:24,000
Finally, the third one is called 'pass'.

46
00:02:24,000 --> 00:02:28,020
And pass is, well, not very useful.

47
00:02:28,020 --> 00:02:30,510
It essentially does nothing.

48
00:02:30,510 --> 00:02:32,073
If I click 'run' here,

49
00:02:33,720 --> 00:02:36,660
and again it shows me here line 10, something's wrong.

50
00:02:36,660 --> 00:02:40,800
Well, we have to move print up to the top so that while,

51
00:02:40,800 --> 00:02:45,800
we don't get my list of index of three, which doesn't exist.

52
00:02:47,340 --> 00:02:49,737
So again, going back here, if I click 'run',

53
00:02:50,670 --> 00:02:52,980
pass doesn't do absolutely anything.

54
00:02:52,980 --> 00:02:57,150
It just essentially passes to the next line.

55
00:02:57,150 --> 00:03:00,150
So why is that ever useful?

56
00:03:00,150 --> 00:03:03,390
It's very rare that you'll see 'pass' in your code,

57
00:03:03,390 --> 00:03:06,540
but 'pass' is a good way to have, let's say,

58
00:03:06,540 --> 00:03:08,730
a placeholder while you're coding.

59
00:03:08,730 --> 00:03:12,510
For example, you wanna loop through the 'for' loop,

60
00:03:12,510 --> 00:03:15,030
but we don't know what we wanna do yet, in the code.

61
00:03:15,030 --> 00:03:18,720
Let's say that here, we're still thinking about it.

62
00:03:18,720 --> 00:03:21,297
If I do this and I click 'run',

63
00:03:22,740 --> 00:03:26,090
I get an error here because, whoa, whoa, whoa...

64
00:03:27,360 --> 00:03:29,010
'Expected an indented block.'

65
00:03:29,010 --> 00:03:33,000
Because now, the 'for' Loop or the Python interpreter,

66
00:03:33,000 --> 00:03:34,747
is looking for the next, like,

67
00:03:34,747 --> 00:03:36,067
"What am I supposed to do with the Loop?"

68
00:03:36,067 --> 00:03:38,490
"I'm trying to loop and there's no code for me."

69
00:03:38,490 --> 00:03:43,230
So, you can add a 'pass' here to at least fill something

70
00:03:43,230 --> 00:03:44,287
for the 'for' Loop to say,

71
00:03:44,287 --> 00:03:47,370
"Hey, I'm thinking about it, I'm just gonna pass it for now,

72
00:03:47,370 --> 00:03:49,800
just so you have something so you don't bug me,

73
00:03:49,800 --> 00:03:51,180
and I'll come back to it."

74
00:03:51,180 --> 00:03:54,290
So if I click 'run', that still works.

75
00:03:54,290 --> 00:03:57,510
So 'pass' is one of those placeholders that we can use

76
00:03:57,510 --> 00:03:59,400
so that there is a line of code that

77
00:03:59,400 --> 00:04:02,250
does absolutely nothing, that we can still pass through.

78
00:04:02,250 --> 00:04:05,130
Again, a very rare thing to see in production code,

79
00:04:05,130 --> 00:04:06,630
but while you're developing,

80
00:04:06,630 --> 00:04:09,690
some developers like using 'pass.'

81
00:04:09,690 --> 00:04:10,590
And there you have it.

82
00:04:10,590 --> 00:04:12,930
Break, continue, and pass.

83
00:04:12,930 --> 00:04:14,310
I'll see you in the next one.

84
00:04:14,310 --> 00:04:15,143
Bye bye.

