1 00:00:00,600 --> 00:00:11,190 Hello and welcome to this lecture on do while loops do while loops are slightly identical to the while 2 00:00:11,190 --> 00:00:13,940 loops. 3 00:00:14,010 --> 00:00:23,220 The main difference between the two while loops on the wire loops is that the dual while loops will 4 00:00:23,340 --> 00:00:34,970 evaluate the expression at the bottom of the loop while the while loop violates expression off the top. 5 00:00:35,700 --> 00:00:43,290 So what that means is that with a do while loop you almost guarantee that the statement within the do 6 00:00:43,290 --> 00:00:50,860 block are always executed at least once. 7 00:00:50,990 --> 00:00:57,160 Right so this was the code block we used for a while loop illustration. 8 00:00:57,180 --> 00:01:04,910 So I'm just gonna modify this code a little bit to illustrate the do while loop. 9 00:01:05,010 --> 00:01:07,470 So here I'm gonna change this count here. 10 00:01:07,480 --> 00:01:17,390 Will it change the count values to 4 and here instead of a while I'm just gonna type in a DO 11 00:01:21,630 --> 00:01:23,870 AND I'M NOT GOING TO. 12 00:01:23,910 --> 00:01:25,280 THERE'S NOT GONNA BE ANY 13 00:01:28,610 --> 00:01:34,280 no conditions set there because it will evaluate the condition at the bottom here. 14 00:01:34,290 --> 00:01:37,200 So this message will leave here. 15 00:01:37,200 --> 00:01:38,500 So here's to mess. 16 00:01:38,520 --> 00:01:45,250 This is a code that will execute if the expression I'm going to specify in the while loop in the while 17 00:01:45,270 --> 00:01:53,390 condition is true so it will show are just changes values to execute something else 18 00:01:57,680 --> 00:02:00,090 I just want a simple message so just typing 19 00:02:04,080 --> 00:02:04,590 loop 20 00:02:06,870 --> 00:02:07,830 executed 21 00:02:15,690 --> 00:02:20,800 sucks X fully. 22 00:02:21,510 --> 00:02:27,420 So this is a piece of code that will execute so it will display a message. 23 00:02:27,420 --> 00:02:30,930 So this is where I now specify the condition. 24 00:02:30,930 --> 00:02:32,180 So we a do loop. 25 00:02:32,190 --> 00:02:37,580 It doesn't evaluate it doesn't check the condition until the end here. 26 00:02:37,590 --> 00:02:42,730 So in that case this piece of code here would have executed at least once. 27 00:02:42,840 --> 00:02:44,340 So inside here. 28 00:02:44,340 --> 00:02:46,560 This is why I need to specify a while. 29 00:02:46,590 --> 00:02:49,990 Because it's a do while loop. 30 00:02:50,250 --> 00:02:55,450 So the expression no the condition is checked inside the wild part. 31 00:02:56,130 --> 00:03:09,510 So I'll typing while and then I'll say count which is a variable is less than 0 equals 2 for 32 00:03:14,260 --> 00:03:14,720 all right. 33 00:03:14,750 --> 00:03:23,460 So if I run this code as long as this condition is met this piece of code will continue to execute. 34 00:03:23,510 --> 00:03:31,970 So let me run that click Start and wait for the form to load. 35 00:03:32,150 --> 00:03:37,580 So watch as I click on the form on the button says. 36 00:03:37,580 --> 00:03:43,430 Loop executed successfully loop executed successfully. 37 00:03:43,460 --> 00:03:44,780 So you keep saying that 38 00:03:52,210 --> 00:03:54,350 our cat just jumped into the code. 39 00:03:54,380 --> 00:03:59,440 I missed something because I want the way I've set it up at the moment. 40 00:03:59,480 --> 00:04:06,200 The condition will always be true so I need to specify an increment. 41 00:04:06,200 --> 00:04:14,060 So the way you do that is I'm just going to get rid of this bit here. 42 00:04:16,280 --> 00:04:18,520 And time pain count 43 00:04:26,920 --> 00:04:36,570 plus plus what this plus plus means is that it will increase the value of the count by one. 44 00:04:36,570 --> 00:04:39,860 So eventually this condition will become force. 45 00:04:39,990 --> 00:04:48,020 The way I had the codes set up previously before I run the code it will always be true. 46 00:04:48,030 --> 00:04:50,840 In that case the loop will never end. 47 00:04:50,850 --> 00:04:54,720 So behold now become an infinite loop because the condition will always be true. 48 00:04:54,720 --> 00:04:55,130 Bye bye. 49 00:04:55,130 --> 00:04:57,440 Put an account to account here. 50 00:04:57,520 --> 00:04:58,500 I'm increasing. 51 00:04:58,500 --> 00:05:04,500 This is a variable I'm saying that each time the loop is executed increase the value by 1. 52 00:05:04,620 --> 00:05:11,540 So by increasing it each time you run it eventually it will exceed 4 and the condition would be force 53 00:05:12,720 --> 00:05:15,630 which makes the code stop executing. 54 00:05:16,110 --> 00:05:17,240 So let's start that again. 55 00:05:17,250 --> 00:05:23,520 Click Start and click on the button that's 1 56 00:05:26,520 --> 00:05:36,430 2 3 4. 57 00:05:37,370 --> 00:05:46,210 I have had to change the value of the variable here to 1 because I had it set 2 4. 58 00:05:46,490 --> 00:05:53,960 So what I meant was that the value or set to 4 and so the increment this counts here obviously did not 59 00:05:53,960 --> 00:05:59,430 make any difference because once the value was 4 here each time you increase it. 60 00:05:59,660 --> 00:06:02,180 It doesn't this condition will not be met. 61 00:06:02,780 --> 00:06:06,200 So as he continues to loop. 62 00:06:06,380 --> 00:06:13,490 So what I've done have changed the value to have changed the value of the variable called Count to 1. 63 00:06:13,550 --> 00:06:17,760 So each time we click on the button the count will increase. 64 00:06:17,790 --> 00:06:19,560 So you click on the button. 65 00:06:19,640 --> 00:06:24,550 This will be executed so it will now be one instance. 66 00:06:24,560 --> 00:06:27,650 You click on it again they'll be 2 3 4. 67 00:06:27,980 --> 00:06:33,500 So once you've clicked on it four times then that count would have increased to 4 and the code will 68 00:06:33,500 --> 00:06:35,090 stop executing. 69 00:06:35,180 --> 00:06:36,350 So let's give that a go. 70 00:06:36,350 --> 00:06:39,410 Sorry if I may have confused you with that. 71 00:06:39,460 --> 00:06:41,350 So let's run that again click start. 72 00:06:42,920 --> 00:06:45,320 Alright so watch out for this button. 73 00:06:45,460 --> 00:06:48,190 I will once I click on it once. 74 00:06:48,250 --> 00:06:55,280 The message should display and until I click the message four times we should include indicators account 75 00:06:55,280 --> 00:07:00,700 or for the message will not disappear until the count is over. 76 00:07:00,700 --> 00:07:03,320 So does the button click one. 77 00:07:03,430 --> 00:07:08,290 So this is a first loop count that is a first count. 78 00:07:08,290 --> 00:07:13,350 If I click okay there will be two click okay again they'll be three okay again. 79 00:07:13,360 --> 00:07:17,790 Now before I click okay again it then should disappear. 80 00:07:18,010 --> 00:07:18,390 All right. 81 00:07:18,400 --> 00:07:26,260 So that's the count so once the exceeds for as long as the count is equal to all not greater than 4 82 00:07:27,220 --> 00:07:29,190 it will continue to execute that code. 83 00:07:29,200 --> 00:07:33,130 But once he exceed that count it called to stop running. 84 00:07:33,130 --> 00:07:36,090 So as you can see it has stop running. 85 00:07:36,670 --> 00:07:42,640 This message has stopped showing up so this is a message that will keep showing up as long as this condition 86 00:07:42,640 --> 00:07:46,250 in the wild in the wild part of it is true. 87 00:07:46,360 --> 00:07:49,960 So that is it for this lecture in this lecture. 88 00:07:49,960 --> 00:07:58,510 We learnt about a do while loop so they say there's a difference between a while loop and a do while 89 00:07:58,510 --> 00:08:02,850 loop with the do while loop. 90 00:08:03,070 --> 00:08:10,840 The expression is evaluated at the end here while with a while loop it evaluates at the top. 91 00:08:10,900 --> 00:08:19,630 So what they do while the code is bound to run at least once before it evaluates the condition in the 92 00:08:19,630 --> 00:08:21,250 wild part of it. 93 00:08:21,250 --> 00:08:22,540 Thank you for watching. 94 00:08:22,540 --> 00:08:23,420 Bye for now.