Hey guys, this is Master Jake. It’s 1:05 in the morning and I’m still up as usual, so can be making some videos. I got four or five to hopefully get this week done, so I can just upload them. Otherwise, sorry this came out late, I couldn’t really make a video yesterday but it’s coming out now.
We left off in a statement and we’re going to be needing a bunch of statements here pretty soon or at least it’s good to know them because I am going to be using stuff that uses them and you’ll need to know the statements.
So today, we’re going to be going over the while statement and the do while I actually never used but I’ll show it anyway, if I can remember how to use it. All right, so open up a standard page for your document here. We’re going to create a variable called counter and set it one.
Now the while statement basically says, while this is true; do this and this will loop like each statements, they don’t loop, they just run once and test the statement above. While, as you can understand by the keyword, it’s saying this is true, do this. So as long as whatever is imprints says stays true, this continue to loop over and over again. And be careful with these because you can crash stuff if you’re being stupid or something.
Bu anyway, so the keywords while and then put parenthesis, whatever you want the statement in there and then opening and closing curly brackets then whatever you want to do inside here. You’re going to say, ‘$counter < 10’ and then inside here we’re going to echo the value of counter and when we get with the blond berry so it goes down the line and then we are going to—let me think—oh yeah $counter++; it’s going to increment the value of counter about one.
So if you haven’t, never seen this, typing a variable and then typing ++ will increment about one which mean plus it by one. So if it’s one, it will become two. If it’s two, it will become three. I am not sure if you can do this in PHP but in some way you can just put it before it to which means it will increment it before it even you know. Increment it before even looks at the variable. I don’t really know how to explain that but anyway, I am not sure if you can do that in page but you know you can try it out.
There is also a minus-minus statement, which will increate it by one. So if it’s three, it will be two, it it’s two, it will be one, etc. Or you can just do $counter = $counter + 1 or you do $counter += 1, so many ways to do this.
We’re just going to go with the most simple into the ++ right now. We’ll save it—going to save it as while.php and these are dragging into my accent projects and open up Firefox to load this.
By the way, I’m at my moms right now and she’d be getting internet you know this week, so you won’t ever see this screen hopefully; Address not found, pop. Stop being gay, all right. Let’s go into the project’s folder, find the this sucker. It’s down here I’ll see what happens 1, 2, 3, 4, 5, 6, 7, 8, 9. It only printed up to nine and it’s kind of difficult to tell if you want it to count all the way to ten, you got to really think about it because, we’ll look at while statement here, it says while ($while counter < 10) and down here at the bottom, it’s—let’s say its nine. It’s nine and then down here at the bottom, it’s going to go to ten then when it goes back up to check the loop again, it’s already ten, so it’s not less than ten, it will just skip it.
So to fix that, you can just said—let’s less than or equal to ten while ($counter <= 10) Save and Reload and the it will count all the way up to ten. So that’s how you do that, it’s pretty nifty I guess. Now let’s—you can you know, screw around with that, see what you can do.
Now do while is a little bit different. Do while, while, this while right here checks the statement before it does whatever you want it to do like it’s going to check at the top. If counter is less and are equal to ten, if it’s not, it’s just going to skip it. But if it’s true, it will go on through and then going way to the top to check the next statement.
Do while does whatever you tell it to do before it checks it; stuff here. All right so, it’s always going to at least run once. This—the do while loop is always guaranteed to run at least once. So we’ll take $counter = 1 for instance.
We’ll do echo $counter . “
”; while($counter > 1) and $counter = 1, so you think that’s wouldn’t work but when you save it and run it, it’s going to act all out one because it’s doing whatever you tell it to do before it even checks.
So after it gets done doing this, it will check the while and if its still true, it will run and do it again but if it’s false, then it will stop. We can do that last thing; ten thing again, you can actually do just regular less than 10 this time, it shouldn’t be able to work. Let’s try it—oh I forgot to increment it.
That’s why I am talking about being stupid because if you don’t increment the value, then it’s always going to be less than ten, it’s just going to loop forever and crash your internet browser. Believe I’ve done that a lot. I have the $counter++; here at the bottom. I don’t know if this will—no, it just counted up to nine.
See this crap here is confusing if you think about it but yeah, I mean it makes sense now because it’s nine in it , increments it right here. And that makes it ten and it’s—once it checks it’s not less that ten anymore so you do need the less and equal to.
But yeah, that’s pretty the while and do while loops, it’s pretty simple to understand, they’re not that big deal. Now what you do notice is that the—for do while, it’s do then stuffing curly brackets, then you talk while with me it will have to follow through and you got in that with those going. I’m pretty sure, let me try some. See if this gets me there, yeah it does. So you do need end that with semi colon. Some things are like that and some aren’t, it really depends but yeah.
Bu that’s the while and do while loop. Thanks for watching the video and the next would be coming out about five seconds because I am going to record like 30 to 9, no I’m just kidding but probably 4 or 5 and I’m going to be releasing this one along with another one because I missed yesterday as I so kindly apologize but anyway I’ll stop talking.
Transcription by:
Scribe4you Transcription Services