William Rosener: Let's talk to Bill. Welcome back. And this video you'll learn how to do while loop, which is going to allow instructions to be executed numerous times, based on some condition.
William Rosener: Let's start by taking a look at what you learn how to do and then we'll get started there so I can print off the start. We'll start off printing off the numbers one to 10 years in a do while loop.
William Rosener: Then we'll go in the opposite direction. Using a do while loop that will print off even numbers between two and 20
William Rosener: And increase. And then finally, in decreasing order there, there won't allow the user to create a personalized loop. In this case, we're going to go from five to 100 increments of five.
William Rosener: And those who have 12345678 columns and I wanted to, I could change that.
William Rosener: And I've got it in four columns there. OK, now that we won't know what to do. Let's get started. There
William Rosener: So in the same area as you fill in the link to this video, you should also find the interface. And we're going to be recreating this using the do while loop here. So I'm gonna go ahead and double click on the first one here, one to 10
William Rosener: I do, but before doing that. I should probably let's just take a second here. And we'll find out what this thing is called and this thing is called LPL results. That's what I'll be placing my information there.
William Rosener: Okay, so the very first step. I'm gonna do is, let's say, remember to come up here and turn on Option Explicit
William Rosener: So if I get a mistake terrible name I'm gonna get a little warning message them. So the very first step. I'm gonna do is I create a variable called calendar.
William Rosener: And I'm going to go ahead and set countered equal to one. I'm not going to go do wild counter is less than reported 10 again I'm printing numbers one to 10
William Rosener: Say LBO
William Rosener: Results.
William Rosener: The
William Rosener: Results.
William Rosener: caffeinated with counter
William Rosener: Increment my calendar and if I forget this. I'm going to get into an infinite loop.
William Rosener: And Luke. So if I was to leave this one line off. I'm gonna set counter. Good one. So counters. One is one less than 10 yes it's going to display.
William Rosener: Comeback is one less than 10 less than 10 one less than 10 and you're getting into an infinite loop. And there's some keyboard shortcuts that you can press to terminate that loop or if you wait about five minutes. Typically, it will time itself out there.
William Rosener: Okay, let's just go ahead and run this here. Let's see what we've got.
William Rosener: Going to press one to 10 and sure enough, we're now putting the numbers one to 10 years and they do all of them. Let's just go through a little space, though.
William Rosener: Sometimes can come right out after this and put a little space so concatenate a space to the in there. So now I need to create a clear button here.
William Rosener: Somebody come on down here, too. So it's great to clear it, let's say, I'll be all results is equal to the knowledge string there.
William Rosener: OK, now I run it, I can clear it. And sure enough, I'm putting the numbers one to 10. Now let's go ahead and do that in the opposite direction will print 10 down to one and it's going to be loop number two.
William Rosener: Again, I'm going to create a variable or just call the same thing counter
William Rosener: Counter equal in this case. And I'm gonna go do while his counter
William Rosener: Greater than or equal to one.
William Rosener: So I'm just saying results.
William Rosener: With counter
William Rosener: Space, the big thing here. I need to take counter
William Rosener: Minus one.
William Rosener: And in my loop.
William Rosener: Someone said counter to 10 is 10 greater than or equal to one. Yes, it's in the loop concatenate 10 in a space to results and I subtract one. It's now nine I come back as nine greater than one. Yes, is sacred. Of the one except for them.
William Rosener: Okay, let's go ahead and check this out.
William Rosener: So let me clear that and sure enough for now print the numbers and decrease in order from 10 down to one. OK, now let's go ahead and this is Luke three. And just to save a little time I'm gonna grab the kid from loop one copy and paste that
William Rosener: And in this case here. I want to start at 200 put the numbers from two to 20 somebody go to 20 and then committing by two.
William Rosener: Okay so started to go to 20 increments by two.
William Rosener: Okay, and that's working beautifully. Okay, now one more simple one. Before we move on to the personalized loop.
William Rosener: Okay, here's a loop form. And if you ever want sometimes definitely in the classroom. I like to
William Rosener: So I just took that and I'm going to paste it up here and I'm in a classroom I typically like to have the code at the top of someone's in the back there. So I'm just going to grab the code here. This was a loop three
William Rosener: If you do have it. They said, just make sure you grab the private SUV and in 70 wrap everything
William Rosener: Up. So I want to loop to some I grabbed a carrot here for loop to I'm working on, look for and paste. So look for. I want to start at 20
William Rosener: Is it grid and equal to, to
William Rosener: Subtract two. So we started 20
William Rosener: Subtract to
William Rosener: Accepted them and they said, check this out.
William Rosener: Clear ensure enough for now go in and decrease in order a pizza to there ok now ready to start on our personalized loop.
William Rosener: It again let me copy this and paste it up here at the top.
William Rosener: This really matter if you're taking this course online. But again, sometimes I just like to
William Rosener: Add more towards the top of the screen there. Okay, so we're going to go ahead and create some of the variables here just like we've been doing counter. I'm also going to create one called column counter, which is going to count the number of columns, though.
William Rosener: OK. And I'm going to go ahead and set my
William Rosener: Altar
William Rosener: It's equal to all table, we should probably look at these quickly it's txt star. But just to show you here.
William Rosener: I press on that txt start this what is called txt end
William Rosener: txt increment detriment and txt columns within so
William Rosener: Okay, so I'm going to set counter equal to the value and txt
William Rosener: Start
William Rosener: Now I'm going to go ahead and I'll tell you what, if I wanted to, I could set my column counter. I'm gonna, I'm not worried me with this yet.
William Rosener: This is going to allow me to format my my output and columns, but I'm gonna i'll go ahead sentences earlier. Okay, let me go wow counter is less than or equal to
William Rosener: Value in txt and
William Rosener: They will, let's just grab grab located here on display it.
William Rosener: We've got some work to do. But actually, typically, I'm in debt.
William Rosener: So counter equals calendar plus one.
William Rosener: And Luke and let's see if we get into six. There are some staking display encounter many invite one here. Let me go five to 55 out here.
William Rosener: And sure enough for now going five to 50 567 all the numbers between five and 15. Now let's go ahead and take advantage of. Take a look at the information increment detriment.
William Rosener: And I'm just going to come right out here.
William Rosener: Rather than adding one common add the value and txt
William Rosener: excrement.
William Rosener: Clear and personalized so five to 50
William Rosener: increments of five. So if I wanted to put
William Rosener: I could go if I wanted to point out that even numbers are but agreements of 10 like 10 2030 acceptor there.
William Rosener: And sure enough, it's working there okay let's now start working on
William Rosener: Display in this into columns. Okay, I'm gonna come right back here to my kid.
William Rosener: I'm gonna come right up here.
William Rosener: inside the loop.
William Rosener: Going to take a look. First of all I'm gonna do is on the say column.
William Rosener: And you typically find that however my variable is declare this I'll notice it's lowercase here when I hit the enter key here in a second. And I'm gonna say column calendar plus one.
William Rosener: Okay. And since this one was declared with a capital C, this is what he became like came right up here and they this lower see
William Rosener: Notice how it automatically adjusted that I like this example.
William Rosener: Okay, so I'm gonna set my con counter because one so I came along. I have displayed one piece of data for the space. I'm not gonna say counter equals counter plus one.
William Rosener: I'm going to take a look at my colleague counter
William Rosener: That is equal to
William Rosener: The value in to
William Rosener: Columns.
William Rosener: Then what I want to do is concatenate a new line on the end of that and how do I do that, I'm gonna take what's in there'll be a results.
William Rosener: And concatenate it's a CH AR 13 and that's the value for new line.
William Rosener: Out here.
William Rosener: And now what I want to do. So I put the new one is I want to reset like home counter
William Rosener: Back to zero.
William Rosener: Okay. Let's check it out. So what's going to happen is I'm going to print like let's say five it's equal to have all my printed out five and not put concatenate a CH AR 13 which is going to cause inflammation wrapped to the next one. There
William Rosener: Okay, let's hit personalized loop and sure enough I got 12345 I was changes to a 612345 611 that's just go ahead and format this a little bit better here just so we kind of get everything and nice some columns.
William Rosener: So I'm gonna come right along. Come right back here and what I'm gonna do is I'm gonna put a little if statement here.
William Rosener: To say if
William Rosener: It's less than equal to 10
William Rosener: And then we want three spaces here.
William Rosener: 123
William Rosener: That's all one word calendar is less than 100
William Rosener: If it's less than
William Rosener: two digits.
William Rosener: Two spaces.
William Rosener: One space.
William Rosener: Statement, which is towards though.
William Rosener: Okay, I think we're ready to check this out.
William Rosener: Clear personalized loop. Sure enough, I'm now getting
William Rosener: Increments I'm going to 100 increments of five and look at six columns that was to change this to
William Rosener: Change it to form.
William Rosener: 1234 hopefully this video you learned about the do while loop, which, again, it's going to execute instructions multiple times and tell a condition is met. What that condition is met. It's going to exit the loop. Okay, next video. Thanks.