1 00:00:00,240 --> 00:00:01,260 All right, so. 2 00:00:01,260 --> 00:00:02,010 While loop. 3 00:00:02,010 --> 00:00:03,720 We checked before hand, right? 4 00:00:03,720 --> 00:00:05,480 I wouldn't of had to keep on asking that, 5 00:00:05,480 --> 00:00:07,960 wouldn't have keep on doing that loop if I didn't ask for it. 6 00:00:07,960 --> 00:00:09,330 Now let's do a do while loop, okay. 7 00:00:09,330 --> 00:00:10,290 So a do while loop. 8 00:00:10,290 --> 00:00:11,400 It's the same concept, right. 9 00:00:11,400 --> 00:00:12,860 We don't know how many times it's going to happen but 10 00:00:12,860 --> 00:00:14,830 we do know that we want it to happen one time. 11 00:00:14,830 --> 00:00:17,050 Right, so it does what's called a post check. 12 00:00:17,050 --> 00:00:21,100 So this is useful when you want to make sure that one time it happens. 13 00:00:21,100 --> 00:00:23,030 So. The example that I have for this, 14 00:00:23,030 --> 00:00:24,410 we're totally shifting examples here. 15 00:00:24,410 --> 00:00:28,350 The example that I have for this one, this pseudo code is Mini-Golf, right? 16 00:00:28,350 --> 00:00:30,540 So, you can't get a hole in zero. 17 00:00:30,540 --> 00:00:31,830 You have to get a hole in one, right? 18 00:00:31,830 --> 00:00:32,560 That's the best you can do. 19 00:00:32,560 --> 00:00:34,430 So you gotta putt once, okay? 20 00:00:34,430 --> 00:00:36,060 So we're gonna say do. 21 00:00:37,230 --> 00:00:39,990 Where, is the ball in the hole is a Boolean over here. 22 00:00:39,990 --> 00:00:41,020 I should've said, is the ball in the hole? 23 00:00:41,020 --> 00:00:42,250 See, I'm bad at pseduo-code. 24 00:00:42,250 --> 00:00:43,310 And we do puttPutt. 25 00:00:43,310 --> 00:00:47,510 We're gonna call and see if we hit that ball in the hole and 26 00:00:47,510 --> 00:00:50,920 until here, that's actually, while not. 27 00:00:50,920 --> 00:00:52,370 Right? In English, too, if you wanted to say, 28 00:00:52,370 --> 00:00:55,960 until something happens, you're really saying, wow, this isn't happening. 29 00:00:55,960 --> 00:01:00,590 Right? So, until is a verb, or a whatever 30 00:01:00,590 --> 00:01:04,980 type of word that is in other programming languages is a keyword in other type of 31 00:01:04,980 --> 00:01:08,530 programming languages, and it really means while not, but Java does not have that. 32 00:01:08,530 --> 00:01:11,500 So we're gonna do, well, let's code it. 33 00:01:11,500 --> 00:01:12,860 So cross your fingers for me, here we go. 34 00:01:12,860 --> 00:01:14,240 Some more live code. 35 00:01:14,240 --> 00:01:14,890 All right. 36 00:01:14,890 --> 00:01:16,000 So, mini golf. 37 00:01:17,910 --> 00:01:22,070 All right, so I imported something that we probably have not talked on yet. 38 00:01:22,070 --> 00:01:24,670 It's handy for testing and example things like this. 39 00:01:24,670 --> 00:01:26,570 It's randomness, right. 40 00:01:26,570 --> 00:01:29,320 It's gonna allow us the ability to give a 50/50 thing, right. 41 00:01:29,320 --> 00:01:32,000 So I don't know about you but my mini golf skills is not 50/50, 42 00:01:32,000 --> 00:01:36,840 I usually have about 99, you know I take a very long time to go through. 43 00:01:36,840 --> 00:01:40,560 So what we'll do is we want one time, we want to do a putt putt. 44 00:01:40,560 --> 00:01:44,470 And let's keep track of it so that we can see how bad we did. 45 00:01:44,470 --> 00:01:46,040 Or how bad the computer did, actually, right? 46 00:01:46,040 --> 00:01:48,380 So we're gonna do numberOfPutts. 47 00:01:48,380 --> 00:01:51,460 Such a weird word, you know, how like when you're typing words and you're like, 48 00:01:51,460 --> 00:01:52,990 is that really how you spell putt? 49 00:01:52,990 --> 00:01:53,880 I don't know. 50 00:01:53,880 --> 00:01:54,670 And putts, too, like. 51 00:01:54,670 --> 00:01:55,700 All right. 52 00:01:55,700 --> 00:01:59,350 So, boolean ballInHole is gonna be false. 53 00:01:59,350 --> 00:02:01,640 We're gonna start out with it false, right? 54 00:02:01,640 --> 00:02:05,990 So the do while loop, we're gonna say do while, and 55 00:02:05,990 --> 00:02:10,096 this is where we're doing the end tells, so not the ballInHole, right? 56 00:02:10,096 --> 00:02:12,500 So it's a little strange, right? 57 00:02:12,500 --> 00:02:14,270 So you're thinking, while the ball isn't in the hole, 58 00:02:14,270 --> 00:02:16,270 while that's not true, keep on looping, okay? 59 00:02:17,400 --> 00:02:23,090 Let's just print out something so we know that we're put that's not great. 60 00:02:24,230 --> 00:02:25,230 Alright. 61 00:02:25,230 --> 00:02:28,870 So let's use that random generator. 62 00:02:28,870 --> 00:02:30,070 And I called that thing luck, 63 00:02:30,070 --> 00:02:34,200 I called the variable luck, which is what you need when you're doing this stuff. 64 00:02:34,200 --> 00:02:39,080 And it has random has the opportunity to return numbers or 65 00:02:39,080 --> 00:02:41,720 other random things, one of the things that can return is a Boolean. 66 00:02:41,720 --> 00:02:44,370 And remember, Booleans are true or false. 67 00:02:44,370 --> 00:02:47,260 We're setting ballInHole to the Boolean, so therefore when it comes to check, 68 00:02:47,260 --> 00:02:49,400 we'll see, we want to increment. 69 00:02:49,400 --> 00:02:52,810 I don't know if everybody knows what this incrementing is or 70 00:02:52,810 --> 00:02:54,150 if we remember what that is. 71 00:02:54,150 --> 00:02:57,880 What it does is it basically is shorthand for saying, I could say number of putts 72 00:02:57,880 --> 00:03:03,010 equals what number of putts was plus one. 73 00:03:03,010 --> 00:03:06,070 So it just takes whatever's in there and adds one to it. 74 00:03:06,070 --> 00:03:07,360 It's a shorthand. 75 00:03:07,360 --> 00:03:08,280 Let's keep it in there. 76 00:03:09,440 --> 00:03:13,070 We're gonna talk about that a little bit later, too. 77 00:03:13,070 --> 00:03:15,460 All right. 78 00:03:15,460 --> 00:03:17,330 For sure one time it goes through. 79 00:03:17,330 --> 00:03:18,620 It will at least be one, right? 80 00:03:18,620 --> 00:03:19,910 Cuz they tried one time. 81 00:03:19,910 --> 00:03:22,380 And if the ball went in the hole, it would be over, and good job, 82 00:03:22,380 --> 00:03:23,620 we did a hole in one. 83 00:03:23,620 --> 00:03:27,760 But we'll say, you got it in %d, because it's a number. 84 00:03:31,580 --> 00:03:34,810 And we're gonna pass n the number of putts. 85 00:03:34,810 --> 00:03:38,820 What do you say? 86 00:03:38,820 --> 00:03:40,240 I remember that. 87 00:03:40,240 --> 00:03:41,100 Let's do it. 88 00:03:42,770 --> 00:03:44,250 I don't know where my history went. 89 00:03:46,040 --> 00:03:47,750 Let's see. So we'll call this Minigolf. 90 00:03:48,890 --> 00:03:52,570 We're gonna compile Minigolf, and then we are going to run Minigolf. 91 00:03:53,930 --> 00:03:58,640 Don't put the Java extension there. 92 00:03:58,640 --> 00:04:00,880 One, hole in one, we did it randomly. 93 00:04:00,880 --> 00:04:02,035 We randomly did a hole in one! 94 00:04:02,035 --> 00:04:03,040 >> [APPLAUSE] >> Yeah! 95 00:04:03,040 --> 00:04:05,210 Still, a hole in one. 96 00:04:05,210 --> 00:04:06,230 Come on, oh there it is. 97 00:04:06,230 --> 00:04:08,600 Three putts. This should. 98 00:04:10,390 --> 00:04:11,510 Wow, it's doing pretty good. 99 00:04:11,510 --> 00:04:12,950 >> Looks good. 100 00:04:12,950 --> 00:04:13,530 >> There's two putts. 101 00:04:13,530 --> 00:04:14,420 Yeah. >> [LAUGH] 102 00:04:14,420 --> 00:04:14,920 >> Yeah. 103 00:04:14,920 --> 00:04:15,850 Let's go golfing and 104 00:04:15,850 --> 00:04:17,426 let's put some money on it. Cool. 105 00:04:17,426 --> 00:04:18,563 >> [LAUGH]