PHP-and-MySQL/C2/Loops-While-Statement/English

From Script | Spoken-Tutorial
Revision as of 01:54, 21 April 2013 by Pravin1389 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Time Narration
0:00 okay i have decided to do each looping tutorial in a different video because i don't want to confuse anyone.
0:07 i want to keep it simple and also for a reference perhaps if you need to come back and refer to how a particular loop is initialized.how it works.then this i find it much easier to have a separate video
0:22 okay so what we are going to do is we gonna use a while loop
0:25 now a while loop checks for condition at the start at the loop and executes the code depending on whether this condition is true or not
0:35 so for example what I'm gonna do is I'm gonna start my 'while loop' and I'm gonna say this my condition and this my block
0:44 I'll represent it well my block is in between some curly brackets
0:52 okay my condition here.now the thing with this is ,in the last,in the 'if statement' example i used 1=1.
1:02 now if I was to say 'test' or 'loop' here.
1:08 okay there is loop here and then a brake,now what this would do is,as long as 1=1 it would create a loop
1:14 now if i do wrong my brown.so I man you can try these if you want.
1:19 it would probably crash your browser because loop would be repeated as long as 1=1 and which i am afraid is forever.1 will always equal 1
1:29 so therefore loop will always be repeated therefore your browser will be crashed
1:33 so what I can say is I can say while a variable let say 'num' is smaller or equal to 10 and what i can do is under my echo i can say 'num ++'
1:57 now '++' is a arthematical operator.i dint cover my arthematical operator tutorial and what is basically does is it increases 1,it is same as writing 'num =num +1'
2:16 so its taking this and its saying that it is equal to the value of it currently at 1 more.
2:22 okay so this again is a arthematical operator. so basically in our program this is gonna happen
2:29 we are gonna say is 'num' smaller than or equal to2:46 '10'.if so echo loop and then say add 1 on to the valuable
2:46 but what we should really do is create 'num = to 1' at the moment.so loop once at 1 this will then equal 2 then 3 then 4 all the way up to 10 then in which case it will stop
3:02 and then the rest of the code below this will continue
3:06 so we said this 1 and see what will we get. okay we got loop 1,2,3,4,5,6,7,8,10 times
3:20 okay now to make it more fun I'm going to say loop 1 and I'm gonna concatenate 'num' on the end of that
3:29 In fact let's be sensible about it and say 'num' inside that it will make it easier to read
3:37 okay so I'm gonna say loop 1 and add 1 and then I'll say loop 2 and I'll add another one that's loop 3 add another one bla-bla-bla
3:49 lets open this up refresh it there you go, you got loop 1,2,3 all the way up to 10 like you can see
3:57 so you can change this value here to 100 if you like.refresh that.you can see it has gone to hundred.now the bigger you make it the longer it will take
4:09 let's over 6000.let's refresh that.it's gonna take a while and there you go up to six thousand.so it's very efficient in this way
4:20 if you leastwise if you can try combining this with an 'array' to create a program that echoes out of the alphabet inside the 'array'
4:33 you can use loops to echo out every single value of an array
4:36 just give it a go if you fancy it it would probably be in one my tutorial not in the basics section and I probably would do something like that
4:45 however,this is the basics structure. what I also recommend you to do is create a variable here called 'max' and have your maximum value here
4:54 he will do exactly the samething it's just a lot more easy to read and you can declare all this thing up here and this would be a reference to it
5:02 just in case you have more than 1 loop. I prefer it for readability and flexibility for my program.okay so that a while loop and I'll just overview it checks the condition of the start
5:15 if that condition is true. it would execute this block of code and you can do things like 'echo alpha'
5:21 your variable is been implemented.make sure that you do implement your variable otherwise it will loop for infinity.
5:31 okay thanks for watching

Contributors and Content Editors

Pravin1389