1
00:00:00,830 --> 00:00:05,720
No less experimented with the while loop.

2
00:00:05,720 --> 00:00:12,600
So the next example is example five and let's say we want to print zero through four using a while loop.

3
00:00:12,610 --> 00:00:17,150
I'll just copy the header we have here and bring it here and see this is.

4
00:00:17,160 --> 00:00:18,980
Example number five.

5
00:00:19,000 --> 00:00:20,120
This should have been four.

6
00:00:20,110 --> 00:00:21,440
Sorry.

7
00:00:21,490 --> 00:00:23,520
I can see this example number five here

8
00:00:26,750 --> 00:00:33,760
and this time they say we want to print 0 through 4 like this.

9
00:00:34,100 --> 00:00:36,430
Melissa will come here and then we have ever had.

10
00:00:36,430 --> 00:00:37,490
No no no no.

11
00:00:37,510 --> 00:00:39,100
Coursera.

12
00:00:39,100 --> 00:00:41,950
We don't need a semicolon.

13
00:00:41,950 --> 00:00:43,090
And then we can see

14
00:00:45,680 --> 00:00:52,270
for gnome is less than five semicolon.

15
00:00:52,320 --> 00:00:54,710
Now call on here and then print num

16
00:01:00,200 --> 00:01:07,290
then we can come down further and say num plus 1 like this.

17
00:01:08,120 --> 00:01:11,400
So it's going to print this and then add one to num iterate.

18
00:01:11,450 --> 00:01:16,060
This is the iterator this time just like in any other programming language.

19
00:01:16,340 --> 00:01:17,700
So let's see what happens.

20
00:01:17,720 --> 00:01:23,180
Let's see what example 5 prints click over here and then click here to run the module click here.

21
00:01:23,300 --> 00:01:24,090
Okay.

22
00:01:24,140 --> 00:01:28,470
And as you can see we have 0 1 2 3 4 and this is how we get there.

23
00:01:28,490 --> 00:01:34,720
Now let's explore the use of the break key word we can use break to break out of the loop and there's

24
00:01:34,730 --> 00:01:41,480
another word continue which we can use to jump over certain steps in the loop is different from this

25
00:01:41,480 --> 00:01:41,850
though.

26
00:01:41,900 --> 00:01:42,990
Let's see what I mean.

27
00:01:43,130 --> 00:01:51,320
We have example six I just copy and paste this down here and it changed this number five to six and

28
00:01:51,380 --> 00:01:52,560
a simple six.

29
00:01:52,640 --> 00:01:53,480
Right.

30
00:01:53,510 --> 00:01:54,460
So then let's see.

31
00:01:54,500 --> 00:01:57,450
Let's just come up with an example.

32
00:01:58,070 --> 00:02:07,520
Let's say we have a variable count because you say this count of course zero and then we can say wow

33
00:02:07,700 --> 00:02:08,990
true.

34
00:02:08,990 --> 00:02:10,520
So crews have defined word.

35
00:02:10,520 --> 00:02:18,080
We can just use while true here and it's the same eyes while 1 while a true print count the statement

36
00:02:18,080 --> 00:02:22,520
is false cos count because zero zero means force.

37
00:02:22,520 --> 00:02:30,230
So we can say print count while true print count and then over here we can see count plus 1.

38
00:02:30,290 --> 00:02:31,820
This is what we may count true

39
00:02:35,060 --> 00:02:38,900
count plus of course one or count of course count plus one.

40
00:02:38,930 --> 00:02:45,350
And we can see if the count is greater than five.

41
00:02:45,500 --> 00:02:46,840
Greater than or equal to 5.

42
00:02:46,850 --> 00:02:53,720
Yes also fine we can say greater than or equal to 5 meaning if count the value count becomes five then

43
00:02:53,720 --> 00:02:54,650
break.

44
00:02:54,750 --> 00:02:56,290
We got a call on her.

45
00:02:56,320 --> 00:02:58,680
Her colon and then we can just put a break here.

46
00:02:59,380 --> 00:03:05,590
So then this is going to count zero through five right.

47
00:03:05,620 --> 00:03:06,620
So let's see what I mean.

48
00:03:06,640 --> 00:03:08,260
Click over here to run.

49
00:03:08,260 --> 00:03:09,150
Click here to save.

50
00:03:09,160 --> 00:03:10,570
Because I didn't save.

51
00:03:10,570 --> 00:03:11,340
We misspelled.

52
00:03:11,350 --> 00:03:12,480
Can't remember her.

53
00:03:12,500 --> 00:03:14,130
Can't I use that we'll see here.

54
00:03:14,140 --> 00:03:14,860
Sorry about that.

55
00:03:15,520 --> 00:03:17,740
Click here to run it.

56
00:03:17,770 --> 00:03:24,290
OK now she can see an example of success 0 1 2 3 4.

57
00:03:24,370 --> 00:03:29,880
So when you got here while conscious greeted on equal to five it escaped us and it's great.

58
00:03:29,920 --> 00:03:36,460
It would have returned here to print but we used a break statement no less have a much more creative

59
00:03:36,460 --> 00:03:46,600
example less design the script to skip over even numbers so I can come down here and you'll see examples

60
00:03:46,740 --> 00:03:47,400
seven.

61
00:03:47,470 --> 00:03:54,040
Let's cover this example seven and can print here we can give it a title for your revision.

62
00:03:54,060 --> 00:03:55,980
Here this is Kip event.

63
00:03:56,230 --> 00:04:07,750
Numbers like this and we can come in and see a print example seven resorts can come and start with a

64
00:04:07,750 --> 00:04:18,010
for loop we can see four for X and use the range range of 10 minutes zero through nine and then over

65
00:04:18,010 --> 00:04:26,740
here we can have an if condition if X percentage to of course because you.

66
00:04:26,740 --> 00:04:31,630
This is how we would detect an even number if this the case continue.

67
00:04:32,650 --> 00:04:36,940
And then once that is done we can see a print x like this

68
00:04:40,160 --> 00:04:43,930
then we can just click here to save and then run.

69
00:04:44,050 --> 00:04:45,150
We go in.

70
00:04:45,160 --> 00:04:47,760
We just set for X range.

71
00:04:48,310 --> 00:04:49,060
It's very minor.

72
00:04:49,900 --> 00:04:50,440
Okay.

73
00:04:50,440 --> 00:05:00,080
Let's click here to run then okay you can see it's printed just the numbers 1 3 5 7 9.

74
00:05:00,210 --> 00:05:01,230
Right.

75
00:05:01,230 --> 00:05:06,170
So this is a we've had a lot of you know play time with the loops.

76
00:05:06,210 --> 00:05:08,190
I think this is enough examples.

77
00:05:08,190 --> 00:05:16,380
We've treated every use case off the wall and the for loop you have any questions just send me a message

78
00:05:16,380 --> 00:05:21,620
or if you need more explanation just send me a message or leave in the questions area.

79
00:05:21,690 --> 00:05:25,740
So this order is and have a good day I shall see you in the next lesson.
