1
00:00:00,450 --> 00:00:05,720
In the previous video we built this code. The code goes like this.

2
00:00:05,810 --> 00:00:13,580
We assign the empty string to user name variable, and then we build a while loop which checks if this

3
00:00:13,580 --> 00:00:14,930
condition is true.

4
00:00:15,170 --> 00:00:20,020
So if the condition of that user name is different from pypy.

5
00:00:20,420 --> 00:00:25,460
If user name is different from pypy, this is going to be executed.

6
00:00:25,520 --> 00:00:30,410
So in the first iteration user name is actually different from pypy because user name is an empty

7
00:00:30,410 --> 00:00:31,270
string.

8
00:00:31,280 --> 00:00:33,970
Therefore this is going to be executed.

9
00:00:34,010 --> 00:00:42,980
The program asks for the user name. If the input is a for example a will be assigned to user name and

10
00:00:42,980 --> 00:00:44,650
then the second iterations starts.

11
00:00:44,640 --> 00:00:50,540
So while A is different from pypy which is true,
this is going to be executed again.

12
00:00:50,570 --> 00:00:54,110
That's why we get these prompt here again.

13
00:00:54,170 --> 00:01:02,480
If you enter pypy, the loop ends because in the third iteration pypy is not different from

14
00:01:02,480 --> 00:01:04,820
pypy, so this will not occur anymore.

15
00:01:04,820 --> 00:01:12,290
Now there is a different way to do this using a brake statement instead of doing the above.

16
00:01:12,320 --> 00:01:12,770
Let me

17
00:01:18,290 --> 00:01:19,770
do it another way.

18
00:01:19,850 --> 00:01:25,410
Again using the while loop but this time you want to check if true.

19
00:01:26,090 --> 00:01:33,460
While true which is always true so the loop will always execute until we break it, so while true

20
00:01:33,500 --> 00:01:41,260
we want to ask for the user name, input enter the user name.

21
00:01:41,310 --> 00:01:46,020
Now we want to create a conditional here to check inside the while loop.

22
00:01:46,100 --> 00:01:55,550
So if user name is pypy, and break the loop.

23
00:01:55,970 --> 00:01:59,810
Else continue.

24
00:02:00,500 --> 00:02:04,630
Let's see what this will give us Python 3

25
00:02:04,750 --> 00:02:05,840
b.py.

26
00:02:05,860 --> 00:02:08,550
That's the right side script.

27
00:02:08,780 --> 00:02:11,520
Enter username.

28
00:02:11,830 --> 00:02:12,260
Nope.

29
00:02:12,660 --> 00:02:13,600
Nope.

30
00:02:13,620 --> 00:02:14,070
Pypy.

31
00:02:14,970 --> 00:02:15,350
Yes.

32
00:02:16,870 --> 00:02:17,620
Let me try again.

33
00:02:17,650 --> 00:02:21,970
If you enter pypy right away again the loop terminates.

34
00:02:23,370 --> 00:02:28,140
I do prefer this actually because it gives you more control of the workflow.

35
00:02:28,140 --> 00:02:32,970
So this is what's happened here, while true which is always true.

36
00:02:32,970 --> 00:02:39,800
So the first iteration occurs because true is true,
and we ask for the user name in the first iteration.

37
00:02:39,900 --> 00:02:45,470
So in the first iteration here the user name was asfd.

38
00:02:45,660 --> 00:02:54,570
So if asfd is equal to pypy breaks the loop.
That is not the case because asfd is different then

39
00:02:54,570 --> 00:02:55,280
pypy.

40
00:02:55,320 --> 00:03:00,720
Therefore this will not occur because this condition is false.

41
00:03:00,720 --> 00:03:02,310
Else will be executed.

42
00:03:02,400 --> 00:03:03,600
Continue.

43
00:03:03,720 --> 00:03:08,810
Now what continue does is it moves the control on top of the loop again.

44
00:03:08,850 --> 00:03:13,080
So that's how you use break and continue in a while loop.

45
00:03:13,170 --> 00:03:18,090
Both ways are correct but I do find this more readable.

