1
00:00:00,730 --> 00:00:06,640
Hey, in this video, we will look at another wild loop example so that you understand the wild loop

2
00:00:06,640 --> 00:00:08,410
from another perspective.

3
00:00:09,880 --> 00:00:11,870
I'll show you two examples, actually.

4
00:00:11,890 --> 00:00:20,050
The first one is a very small program where we ask the user to enter a password and then we try to check

5
00:00:20,050 --> 00:00:22,420
if the password is correct.

6
00:00:22,450 --> 00:00:27,790
If it is correct, we tell the user that the password was correct.

7
00:00:28,060 --> 00:00:33,370
If it's not, we continue to ask the user to enter a password over and over again.

8
00:00:33,700 --> 00:00:36,610
This is how I would do it with a wild loop.

9
00:00:37,150 --> 00:00:39,010
So think about the user again.

10
00:00:39,010 --> 00:00:40,760
What do you want to show them first?

11
00:00:40,780 --> 00:00:50,080
Well, ask them to enter a password, so get the password from the user using an input function.

12
00:00:51,400 --> 00:00:52,750
Enter password.

13
00:00:54,190 --> 00:00:56,500
So that's the message we show to the user.

14
00:00:57,190 --> 00:01:03,610
The user will enter a password and the password that the user enters will be stored in this password

15
00:01:03,610 --> 00:01:04,269
variable.

16
00:01:04,510 --> 00:01:07,240
Then we check wild passwords.

17
00:01:08,500 --> 00:01:11,830
So while that variable value is.

18
00:01:13,190 --> 00:01:14,900
Not equal to.

19
00:01:16,930 --> 00:01:17,810
Pass.

20
00:01:17,830 --> 00:01:18,760
One, two, three.

21
00:01:18,970 --> 00:01:22,630
So let's suppose that the correct password is pass.

22
00:01:22,630 --> 00:01:23,560
One, two, three.

23
00:01:25,150 --> 00:01:26,940
And that's how we start the loop.

24
00:01:26,950 --> 00:01:29,950
So what is this expression here?

25
00:01:30,880 --> 00:01:32,230
And what is this?

26
00:01:33,430 --> 00:01:35,590
Let me show that to you in the Python console.

27
00:01:36,670 --> 00:01:48,790
You know, if you do pass 1 to 3 equal to pass 1 to 3, what you get is true If I execute this because

28
00:01:48,790 --> 00:01:57,910
this is an equal operator, so you get through the opposite of an equal operator is the not equal operator,

29
00:01:58,090 --> 00:02:03,220
which comes with this exclamation mark instead of two equal operators.

30
00:02:03,220 --> 00:02:05,800
So if I press that, I will get false.

31
00:02:06,900 --> 00:02:16,680
So what I'm saying here is that while the password is not this, then we keep asking the user for a

32
00:02:16,680 --> 00:02:17,220
password.

33
00:02:17,220 --> 00:02:20,610
So we execute that again over and over again.

34
00:02:20,760 --> 00:02:26,190
Otherwise, I will only indent now and go outside of the one loop.

35
00:02:26,910 --> 00:02:32,670
Otherwise we say password was correct.

36
00:02:33,510 --> 00:02:35,160
So let me execute this.

37
00:02:35,160 --> 00:02:36,900
Now enter password.

38
00:02:36,900 --> 00:02:38,910
Let's say pass one.

39
00:02:39,690 --> 00:02:40,800
Oh no.

40
00:02:40,830 --> 00:02:42,330
Pass two.

41
00:02:42,330 --> 00:02:43,610
No pass.

42
00:02:43,620 --> 00:02:44,640
One, two, three.

43
00:02:45,360 --> 00:02:47,670
Yes, password was correct.

44
00:02:49,260 --> 00:02:52,380
So to wrap it up, this is how this code works.

45
00:02:52,440 --> 00:02:55,960
This line here is executed only once.

46
00:02:55,980 --> 00:03:01,590
Everything that is outside a loop is executed only once in Python.

47
00:03:01,740 --> 00:03:07,950
But this expression here is inside the loop, so it will be executed as far as this condition stays

48
00:03:07,950 --> 00:03:08,520
true.

49
00:03:09,030 --> 00:03:12,780
And that condition is dependent on what the user enters here.

50
00:03:13,320 --> 00:03:21,360
So as soon as the password that the user enters is different from pass 1 to 3, we will get this executed

51
00:03:21,360 --> 00:03:22,410
over and over again.

52
00:03:22,890 --> 00:03:27,300
Otherwise, the loop ends and we show the user this message.

53
00:03:27,330 --> 00:03:29,130
That's how this code works.

54
00:03:30,060 --> 00:03:31,290
Another example now.

55
00:03:33,110 --> 00:03:35,090
I'll rename this to.

56
00:03:36,540 --> 00:03:40,320
Bonus to that one and create a new file.

57
00:03:43,000 --> 00:03:44,490
Bonus to the two.

58
00:03:46,150 --> 00:03:52,650
This time I want to use the World Loop to produce a series of numbers as output.

59
00:03:52,660 --> 00:03:57,460
So I want to produce numbers from one, two, three, four, five, six.

60
00:03:57,460 --> 00:04:01,480
So one, two, three, four, five, six will be printed out in the command line.

61
00:04:02,380 --> 00:04:04,390
How can we generate these numbers?

62
00:04:05,140 --> 00:04:09,010
Well, let me show you how using the one loop while.

63
00:04:09,640 --> 00:04:12,550
But we start with a value.

64
00:04:12,910 --> 00:04:15,700
Let's say x is one.

65
00:04:16,149 --> 00:04:17,320
X is a variable.

66
00:04:17,410 --> 00:04:18,910
One is a number.

67
00:04:19,750 --> 00:04:22,630
And we say while x is.

68
00:04:24,190 --> 00:04:26,080
Less or equal.

69
00:04:27,290 --> 00:04:28,310
Then six.

70
00:04:30,280 --> 00:04:31,570
We do something.

71
00:04:32,930 --> 00:04:35,810
And that here is also a comparison.

72
00:04:35,840 --> 00:04:41,000
Operator Just like we had that not equal.

73
00:04:41,000 --> 00:04:43,850
Operator We also had this equal operator.

74
00:04:44,390 --> 00:04:52,700
We also have the comparison Operators such as this one, for example, is one less than three we get

75
00:04:52,700 --> 00:04:56,930
through is one greater than three, we get false.

76
00:04:58,220 --> 00:04:59,420
Similarly, we have.

77
00:05:01,610 --> 00:05:04,010
Less or equal.

78
00:05:04,880 --> 00:05:08,780
So we get true because one is less than three.

79
00:05:09,200 --> 00:05:18,080
If you say it's one less or equal to three, sorry, equal to one, you get true because one is equal

80
00:05:18,080 --> 00:05:18,770
to one.

81
00:05:19,750 --> 00:05:20,530
And so on.

82
00:05:21,880 --> 00:05:23,290
So that's what we're checking here.

83
00:05:23,290 --> 00:05:27,790
If X is one, two, three, four, five or six.

84
00:05:28,540 --> 00:05:31,240
This will be evaluated to try to.

85
00:05:34,810 --> 00:05:38,200
So then I'll print out.

86
00:05:39,350 --> 00:05:39,980
X.

87
00:05:40,850 --> 00:05:46,850
But if I run the script now, what's going to happen is we're going to get one, one, one, one printed

88
00:05:46,850 --> 00:05:48,020
out all the time.

89
00:05:48,020 --> 00:05:49,910
So I have to stop the program now.

90
00:05:49,910 --> 00:05:53,930
Otherwise my processor will get quite busy.

91
00:05:54,930 --> 00:06:03,360
So we get one printed out because X here will always be less than six since its value is one.

92
00:06:03,360 --> 00:06:05,520
So there's no dynamics here.

93
00:06:05,640 --> 00:06:12,870
Nothing is changing x therefore we will get this line printed out all the time.

94
00:06:12,870 --> 00:06:22,440
But if we change x and say x is x plus one, then what we're doing is.

95
00:06:23,390 --> 00:06:25,400
We declare X here equal to one.

96
00:06:25,400 --> 00:06:30,610
We check if X is less or equal to six, which is true.

97
00:06:30,620 --> 00:06:33,290
So we get printed out one.

98
00:06:33,830 --> 00:06:42,290
So in the first iteration we will get one printed out, but then here X will be overwritten with this

99
00:06:42,290 --> 00:06:42,890
value.

100
00:06:42,890 --> 00:06:47,780
So currently x is one, therefore one plus one gives two.

101
00:06:47,780 --> 00:06:54,920
So the new value for x will be two and then the loop goes again.

102
00:06:54,920 --> 00:06:55,760
And here.

103
00:06:56,990 --> 00:07:01,120
X now is two, which is still less than six.

104
00:07:01,130 --> 00:07:11,810
So the loop will print out this again, it will update x, it will say x is equal to two plus one and

105
00:07:11,810 --> 00:07:13,820
that will make x three.

106
00:07:14,000 --> 00:07:17,380
The loop goes again, print three and so on.

107
00:07:17,390 --> 00:07:18,650
So let's run this.

108
00:07:20,300 --> 00:07:21,590
And that's the output.

109
00:07:21,860 --> 00:07:24,110
One, two, three, four, five, six.

110
00:07:24,890 --> 00:07:34,070
So that output was also my intention, and I hope this gives you some more understanding about the world

111
00:07:34,070 --> 00:07:34,700
loop.

112
00:07:35,360 --> 00:07:36,500
Thanks for following.

