William Rosener: Welcome back. In this video, you'll learn about loops, allowing code to be executed multiple times. Let's start by taking a look at what you learn and create
William Rosener: In this assignment here. So first of all, we're going to print out the numbers one to 10 so simply in increasing order one to 10
William Rosener: And we'll go ahead and do that. The opposite direction will go 10 down to one using a for loop, then we're going to print off the even numbers between two and 20
William Rosener: It's in the for loop. Then we'll go in the opposite direction 20 down to two. Then we're going to give us a little bit more
William Rosener: I'm going to give them with complete control and they can personalize the loop in this case will start at five. I'll go 200 increments of five and notice I've got four columns here.
William Rosener: So I'm gonna go one. So first of all, I'm going to go from five to 100 and commits a five by 10 1520 and four columns 1234. I'm going to start, start off with, with this one.
William Rosener: By change that to 6123456 columns and then maybe I could get the table. We could do that even numbers. So I could go to two 100
William Rosener: increments of to somebody go to 200 increments of two
William Rosener: And there we go to the hundred increments of two. So we're going to kind of give the user complete control and that case there.
William Rosener: Okay, well, now that we know what to do. Let's get started here. So in the same area as you found this video, you should also find a link to the interface there.
William Rosener: And let's start off by just take a look here as you find out what this thing is called some to go ahead and right click on it, I'm gonna go to properties and I can see this is called LP L results. Okay, so I'm gonna go ahead and double click on the first command button one to 10
William Rosener: And I always like to have Option Explicit turn on this trip I ever find any understand if help me track them mistakes and we put Option Explicit so I am on loop one
William Rosener: And the time when I press on that when I click on it, it's going to execute the code between the private in the center. So the first thing I need to do is create a variable. I'm just going to call a counter and then I'm going to go
William Rosener: Start my loop or counter equals one to 10
William Rosener: And I'm just gonna say, I'll be I'll results.
William Rosener: Is equal to what's an LBO results.
William Rosener: Are there concatenate it with it counter and I'm going to come in, in my loop there. So it's going to set counter equal one. It's going to go one to 10 12345 6am, and it's going to do is take results and concatenate counter. Let's go ahead and check that.
William Rosener: So I'm going to go ahead and press on top one here in notice it's going to go one to 10 what i mean i speak it some spaces in between these numbers are static. I'm gonna go ahead and work on the clear button so I can clear that out.
William Rosener: And I'm just going to type in LB on
William Rosener: Results equals the knowledge string there. Don't you got one right here. I'm gonna kind of fixes that we do two things at once. And I'm just gonna put a space here. So it's going to display counter and then concatenate a space to the end.
William Rosener: OK, so now I can clear it, and now hit to one to 10 it's going to put the display numbers one to 10 and increase in order. Now let's go in a decrease in order
William Rosener: So again, I'm going to clear my variable and it doesn't have to be the same name, I'll tell you. I'll call this one index.
William Rosener: And for index decor this case, I'm going to decrease in order to new one and the little trick here is I'm going to put a negative one here and then the rest of this will be the same sounds good copy them.
William Rosener: Okay, so I'm going to go from 10 down to one step and by negative value I negative one.
William Rosener: Okay, so I will check this one out.
William Rosener: Oops.
William Rosener: That's what I've got a call that so need to put this index here. So just to show you. I was trying to
William Rosener: Be clever here and I'm given a different name for this one had to match, though. Okay. And that was thanks to the opposite explicit because otherwise that could take me a few few seconds to track that thing down.
William Rosener: OK, so now I'm going to go ahead and press
William Rosener: Either one of these. Here's one to 10 and increase in order and here's 10 to one in decreasing order. And now I'm going to go to to 20
William Rosener: increments of to hear
William Rosener: Okay, I'm going to go back to my column this counter here if you want you can grab this card right up here.
William Rosener: Paste it. So we're going to create a variable called calendar.
William Rosener: Now I want to go from two
William Rosener: To 20
William Rosener: Yeah, look, put a positive two for the step and I should probably mentioned this one appear could have had on the default step is one, so you can actually leave it off or you can put it there to one.
William Rosener: So in this case, I'm going to go from two to 20 stepping by two so 2468 so forth there. And I think this one's ready to jack
William Rosener: OK, so now moving on to button three. I'm going to go from two to 20 increments of two there. OK. Now we're going to take this and go the opposite direction.
William Rosener: And
William Rosener: So I'm going to start with 20
William Rosener: Go down to two and big thing here is make sure you put a negative value and on some of these loops, you may get into an infinite loop. And if that happens.
William Rosener: There's a keyboard shortcut to stop that. Or if you're worried about five minutes or so it will timeout. Okay. So in this case, I'm going to go from two down to 27 by negative two.
William Rosener: And there we go. Let's go ahead and check this out.
William Rosener: Sure enough to down to 20 let's run through one more time, one to 10 increasing order 10 to one decreasing two to 20
William Rosener: And 20 down to two. Okay, now we're going to start, allowing the user to specify the start in increments and even the number of columns. So say, go ahead and double click on personalized loop and we'll get working on that kills them.
William Rosener: So I'm going to create a variable called counter. And I'll tell you one day before I even get to further. I'm also going to create one called called counter, which is going to count the number of columns. Okay. And I'm just going to go for counter equals
William Rosener: Okay, well maybe we should I take a look. Make sure we know these things wrong calm. So here it is. This is called
William Rosener: txt start
William Rosener: txt end
William Rosener: txt increment detriment.
William Rosener: And txt columns. Okay. So, coming back here.
William Rosener: I'm going to go from txt start to
William Rosener: Value in txt end
William Rosener: It will start to build this thing slowly.
William Rosener: And I need to grab this key right here.
William Rosener: Okay, so let's see, we've got some work ahead of us, but we're. Got it. Got a good start here. So I'm going to go from my start to my end.
William Rosener: So maybe from one to 10 just taking the information and this concatenate in it, along with the counter.
William Rosener: To my results. Okay, this I go ahead and check this out. It's personal. This is going to go from five all the way to maybe I'll change this to a 50 here momentarily.
William Rosener: So it's going to display the numbers five to 50 567. Okay, now we're going to go ahead and it's actually read the information and increment detriment.
William Rosener: Okay and I'm just going to put it right out here step and I'm going to take the value
William Rosener: And txt
William Rosener: Increment detriment.
William Rosener: That's gonna be my step value.
William Rosener: Okay, so I've got five here. So let's go ahead and clear this
William Rosener: Person personalized loop. And sure enough, or printing the numbers from five to 50 increments of five 510 1527 of them. OK, that's it. I'm going to change this to 100
William Rosener: Okay, now the next step is we want to organize this into columns. So let's go ahead and get started on that.
William Rosener: Okay, so what I've now done is up taking the information and display that right here. So now what I want to do is I'm going to create a there. I've already got my variable called calm counter
William Rosener: So I'm gonna say column counter equals column counter plus one. I've just added another number. And now what I'm gonna do is I'm going to take a look. And I'm going to go is column counter
William Rosener: zero equal to the value
William Rosener: Within txt columns. So if I'm trying to have them printed six columns and my column counter is that six then we want to do is this one. Put hard return or break and how do I do that in BB
William Rosener: Just going to do is concatenate it's a CSR 13 which is the ASCII value or a new line.
William Rosener: Okay, so if I am about printed off six. I'm going to put the new line which is CH AR 13 let me get this little higher on the screen here.
William Rosener: Now what I want to do is set my column counter
William Rosener: To zero, because I have pushed that way back over to the left. And I'll end my statement.
William Rosener: Okay, let's check a look at this. Hopefully it's pretty close soon.
William Rosener: Okay so 123456
William Rosener: Foot four in here.
William Rosener: I'm getting 1234 okay this is looking great. One last little minor change here. I'm going to do is some
William Rosener: Let's see if we can kind of make sure we get these columns, a little bit more organized and there's we could spend hours working on that. Let's just play around with that just a little bit here.
William Rosener: Okay, so what I've done right now is I'm only going to display on display in one space after so I'm just gonna do is, I'm going to modify this just a little bit and I'm going to go yeah if
William Rosener: It's going to be counter
William Rosener: Is less than
William Rosener: 10 if I wanted to put this in parentheses.
William Rosener: So if it's less than 10
William Rosener: Then what am I going to do
William Rosener: I'm going to put I'll put 3123 and a double quote
William Rosener: Killer is less than or equal to 100
William Rosener: We're going to have to
William Rosener: Else.
William Rosener: If statement here.
William Rosener: Okay, so what that's going to do is either display a little bit to show you there's one, two,
William Rosener: Somebody make sure I've had 32123 extra an extra one there.
William Rosener: There were some correct. Let me take a look here, one
William Rosener: And two and that one's got one. Okay. I think it's, it's hard to even Calvin see in there on the screen there.
William Rosener: Okay, let's check that out.
William Rosener: Okay, and that's like a much better there. So now I've kind of got these organized
William Rosener: That are in column so
William Rosener: Okay, now let me just check that put a six in here.
William Rosener: And there we go, 123456 will hopefully this video a little bit about loops and Visual Basic and I'll get you the next video. Thanks. Bye.