1 00:00:03,700 --> 00:00:04,850 So will come again. 2 00:00:04,870 --> 00:00:10,840 This lesson is going to be a very simple lesson we are talking about two other types of control flaws 3 00:00:11,200 --> 00:00:18,820 which are while loops and do while loops very similar to four loops except that they hold different 4 00:00:18,820 --> 00:00:20,680 you know format for writing. 5 00:00:20,680 --> 00:00:23,910 So let's jump into Axford and see how they work. 6 00:00:24,150 --> 00:00:27,770 When I come in here and close this project and make it myself. 7 00:00:27,990 --> 00:00:41,230 Why project the wild project here is how we do a why do why imagine I have let get my or my thing done 8 00:00:41,260 --> 00:00:41,980 as usual. 9 00:00:41,980 --> 00:00:50,650 Imagine I have this I have an integer that in theory is called My integer ideas Krenzel is evil and 10 00:00:50,650 --> 00:00:57,650 I'm going to say why and me a complete so we can see why while condition. 11 00:00:57,820 --> 00:01:01,570 My end is still below 20. 12 00:01:01,600 --> 00:01:07,680 Let's do something that's the a statement let's say a synagogue All right. 13 00:01:08,090 --> 00:01:12,020 Now the value for the eye. 14 00:01:12,070 --> 00:01:15,830 Now this application you fire on it. 15 00:01:15,940 --> 00:01:18,520 It's what's the error that you have. 16 00:01:18,620 --> 00:01:25,930 Oh so it is called My hands my right arm on this application is going to do is going to run this indefinitely 17 00:01:25,960 --> 00:01:28,340 because it says My answer is zero. 18 00:01:28,480 --> 00:01:34,840 While my answer is below 20 keep doing this sort of while block. 19 00:01:34,870 --> 00:01:39,760 We have to actually write something that changes our our expression. 20 00:01:39,820 --> 00:01:45,040 So I'm going to say while that is true save my decrement. 21 00:01:45,100 --> 00:01:48,230 So keep subtracting from it or actually increment. 22 00:01:48,230 --> 00:01:49,260 Or in this case. 23 00:01:49,420 --> 00:01:50,500 So keep going up. 24 00:01:50,500 --> 00:01:54,560 So it goes 0 1 2 3 4 as long as it is below 20. 25 00:01:54,580 --> 00:01:59,940 It will run this let's see that. 26 00:02:00,140 --> 00:02:06,450 And once my project actually compiles builds and runs we should be able to see something in here that 27 00:02:06,450 --> 00:02:15,040 says yes it is 1 2 3 4 all the way to 20 and then it stops. 28 00:02:15,780 --> 00:02:25,050 Now if you are wondering why 20 isn't it true that it's because when it is 19 19 is a smaller than 20. 29 00:02:25,050 --> 00:02:26,430 So this will run. 30 00:02:26,580 --> 00:02:31,290 So my ins becomes 19 plus plus becomes 20. 31 00:02:31,290 --> 00:02:32,320 It prints it. 32 00:02:32,550 --> 00:02:34,440 And then this whole thing finishes. 33 00:02:34,620 --> 00:02:39,410 If you don't want to fall in that you know pitfall essentially you can do this. 34 00:02:39,410 --> 00:02:42,820 You can actually put your incrementation at the end of the while. 35 00:02:42,960 --> 00:02:48,090 So now we will see that it goes from zero to 19. 36 00:02:48,090 --> 00:02:55,650 So that is a wild while loop for us chicks for your expression and then runs your statement. 37 00:02:55,770 --> 00:02:58,980 There is another type in here that is called Dubai. 38 00:02:59,130 --> 00:03:03,150 So I'm going to say do see if it completes it for me. 39 00:03:03,150 --> 00:03:04,820 It doesn't unfortunately. 40 00:03:05,040 --> 00:03:08,570 So I'm going to say do I here's what I want to do. 41 00:03:08,610 --> 00:03:18,330 I want to say and this long this print again or my INS should have written it properly here might in 42 00:03:18,900 --> 00:03:26,220 my end is a percentage or for my of course. 43 00:03:26,220 --> 00:03:32,370 And then this is essentially going to just keep doing what I'm going to do is I'm going to say why. 44 00:03:32,720 --> 00:03:37,210 And then I'm going to give it a condition I'm going to say do Y. 45 00:03:37,440 --> 00:03:39,090 And what's the condition of they want to use. 46 00:03:39,090 --> 00:03:46,370 I want to say Do this for as long as my end is still larger than zero. 47 00:03:46,590 --> 00:03:48,930 So remember my intro was zero. 48 00:03:48,940 --> 00:03:51,710 We push it up all the way to 20. 49 00:03:51,780 --> 00:03:55,760 Now in the do I'm going to say printed and decrement it. 50 00:03:55,770 --> 00:03:58,950 Now my the. 51 00:03:59,220 --> 00:04:03,780 And the difference between a vial and a do one is in the word. 52 00:04:03,800 --> 00:04:10,860 You first check and then you do something in the do what you first do something and then check to see 53 00:04:10,860 --> 00:04:12,520 if that was the case. 54 00:04:12,540 --> 00:04:14,250 So let's run both of these 55 00:04:17,570 --> 00:04:23,300 so to better illustrate that and of course this printed the way you expected it went from zero to 19 56 00:04:23,300 --> 00:04:30,220 and then went from 20 to one let's say after this piece of art in here for a while. 57 00:04:30,410 --> 00:04:35,820 I said it's my aunt to be let's say minus five. 58 00:04:35,890 --> 00:04:40,940 See the condition is it has to be larger than zero and minus five is not. 59 00:04:40,940 --> 00:04:43,210 So let's run. 60 00:04:43,260 --> 00:04:50,280 So you see it runs at least once because the do part doesn't know about the condition it says well let's 61 00:04:50,280 --> 00:04:50,640 do this. 62 00:04:50,640 --> 00:04:51,570 What am I going to do. 63 00:04:51,720 --> 00:04:55,020 And it's like my ears what's my mind says minus five. 64 00:04:55,020 --> 00:04:55,710 Great. 65 00:04:55,740 --> 00:05:02,030 And now let's subtract from it it becomes minus 6 and continue doing as long as I am larger than zero 66 00:05:02,210 --> 00:05:08,970 and says Oh I shouldn't be continuing this anymore because already I have I have crossed the cross the 67 00:05:08,970 --> 00:05:10,700 condition essentially. 68 00:05:10,740 --> 00:05:12,150 So very simple. 69 00:05:12,150 --> 00:05:20,280 Once again Weinman does something for you as long as this condition is true adn do while does it runs 70 00:05:20,310 --> 00:05:23,700 and then checks for the condition just continues. 71 00:05:23,730 --> 00:05:29,220 If you were to write any of these with a follow essentially it would be something like this it would 72 00:05:29,220 --> 00:05:34,990 be for in my say is zero. 73 00:05:35,080 --> 00:05:42,780 A smaller than 20 plus plus and then it would write the body for a quote in here and then incrementation 74 00:05:42,780 --> 00:05:47,370 was happening within the body of the within the condition of the for loop. 75 00:05:47,610 --> 00:05:54,900 I should mention that we will see this sometime in the future that we don't often use wine or two while 76 00:05:54,900 --> 00:06:03,570 for situations where a for loop can be used Bijlee use it for situations when we are iterating or enumerating 77 00:06:03,570 --> 00:06:11,700 in an array or in a dictionary site where we really have to use a while loop because changing incrementing 78 00:06:11,880 --> 00:06:14,810 values is not within our control. 79 00:06:14,820 --> 00:06:20,030 Maybe you're going to read a dictionary and we're just going to the next item in the dictionary and 80 00:06:20,040 --> 00:06:22,080 we don't know how many items are there. 81 00:06:22,230 --> 00:06:24,440 So if we see this sometime in the future. 82 00:06:24,600 --> 00:06:31,710 For now we can almost get away for everything with with a for loop but are just preface this really 83 00:06:31,710 --> 00:06:32,160 quickly. 84 00:06:32,160 --> 00:06:37,170 So you know there is something called the Royland do wine and we'll come back to this at some point 85 00:06:37,170 --> 00:06:38,410 down the track. 86 00:06:38,470 --> 00:06:39,760 All right so let's move to.