Difference between revisions of "PHP-and-MySQL/C2/Loops-While-Statement/English-timed"

From Script | Spoken-Tutorial
Jump to: navigation, search
(Created page with '{| border=1 !Time !Narration |- |0:00 |Hello and welcome. I have decided to create seperate tutorials for each looping statement. |- |0:07 |I want to keep it simple. This will …')
 
Line 3: Line 3:
 
!Narration
 
!Narration
 
|-
 
|-
|0:00
+
|00:00
 
|Hello and welcome.  I have decided to create seperate tutorials for each looping statement.
 
|Hello and welcome.  I have decided to create seperate tutorials for each looping statement.
  
 
|-
 
|-
|0:07
+
|00:07
 
|I want to keep it simple. This will be useful as a reference also if you need to refer to how a particular loop works.
 
|I want to keep it simple. This will be useful as a reference also if you need to refer to how a particular loop works.
  
 
|-
 
|-
|0:17
+
|00:17
 
|In this tutorial, we will learn about the WHILE loop
 
|In this tutorial, we will learn about the WHILE loop
  
 
|-
 
|-
|0:21
+
|00:21
 
|A WHILE loop checks for a condition at the start at the loop and executes the code depending on whether this condition is True or not
 
|A WHILE loop checks for a condition at the start at the loop and executes the code depending on whether this condition is True or not
  
 
|-
 
|-
|0:38
+
|00:38
 
|for example I'll start my 'WHILE loop' here and this is the condition and this is my block.
 
|for example I'll start my 'WHILE loop' here and this is the condition and this is my block.
  
 
|-
 
|-
|0:51
+
|00:51
 
|I'll represent my block between curly brackets.
 
|I'll represent my block between curly brackets.
  
 
|-
 
|-
|0:56
+
|00:56
 
|My condition is here.  Now, in the 'IF statement',  for example I used 1==1.
 
|My condition is here.  Now, in the 'IF statement',  for example I used 1==1.
  
 
|-
 
|-
|1:04
+
|01:04
 
|Now if I say 'test' or 'loop' here.
 
|Now if I say 'test' or 'loop' here.
  
 
|-
 
|-
|1:07
+
|01:07
 
|This is a loop here and then a break.  Now what happens is as long as 1=1, it would create a loop  
 
|This is a loop here and then a break.  Now what happens is as long as 1=1, it would create a loop  
  
 
|-
 
|-
|1:17
+
|01:17
 
|If I do something here, lets try this.  
 
|If I do something here, lets try this.  
  
 
|-
 
|-
|1:22
+
|01:22
 
|It would probably crash your browser because the loop would be repeated as long as 1=1 and for infinite no. of times, 1 will always equal 1.
 
|It would probably crash your browser because the loop would be repeated as long as 1=1 and for infinite no. of times, 1 will always equal 1.
  
 
|-
 
|-
|1:34
+
|01:34
 
|So since the loop will always be repeated, your browser will crash.
 
|So since the loop will always be repeated, your browser will crash.
  
 
|-
 
|-
|1:40
+
|01:40
 
|Lets say while a variable, 'num' is smaller or equal to 10 and under echo i can say - 'num ++'
 
|Lets say while a variable, 'num' is smaller or equal to 10 and under echo i can say - 'num ++'
  
 
|-
 
|-
|1:57
+
|01:57
 
| '++' is an arithmetical operator. And what it basically does is, it increases num by 1.  It is the same as writing 'num =num +1'
 
| '++' is an arithmetical operator. And what it basically does is, it increases num by 1.  It is the same as writing 'num =num +1'
  
 
|-
 
|-
|2:16
+
|02:16
 
|So it takes num and says that it is equal to the value of num plus 1.
 
|So it takes num and says that it is equal to the value of num plus 1.
  
 
|-
 
|-
|2:23
+
|02:23
 
|So this again is an arithmetical operator. What's going to happen is -  
 
|So this again is an arithmetical operator. What's going to happen is -  
 
|-
 
|-
|2:29
+
|02:29
 
|We are going to say 'num' lesser than or equal to '10',  if yes then echo loop and then say add 1 on to the variable num
 
|We are going to say 'num' lesser than or equal to '10',  if yes then echo loop and then say add 1 on to the variable num
  
 
|-
 
|-
|2:41
+
|02:41
 
|But what we should really do is create 'num =  1' at the moment.  So loop once at 1.  This will then equal 2 then 3 then 4 all the way up to 10 and then it will stop
 
|But what we should really do is create 'num =  1' at the moment.  So loop once at 1.  This will then equal 2 then 3 then 4 all the way up to 10 and then it will stop
 
|-
 
|-
|3:01
+
|03:01
 
|After that the rest of the code below this will continue.
 
|After that the rest of the code below this will continue.
  
 
|-
 
|-
|3:06
+
|03:06
 
|So we said this 1 and see what will we get. Okay we got a loop 1,2,3,4,5,6,7,8,9,10 times
 
|So we said this 1 and see what will we get. Okay we got a loop 1,2,3,4,5,6,7,8,9,10 times
  
 
|-
 
|-
|3:20
+
|03:20
 
|Now to make it more fun I'll say loop 1 and I'll concatenate 'num' to the end of that
 
|Now to make it more fun I'll say loop 1 and I'll concatenate 'num' to the end of that
  
 
|-
 
|-
|3:27
+
|03:27
 
|In fact let's make it simpler and say 'num' inside - it will make it much easier to read
 
|In fact let's make it simpler and say 'num' inside - it will make it much easier to read
  
 
|-
 
|-
|3:37
+
|03:37
 
|Okay I'll say loop 1 and add 1 and then I'll say loop 2 and I'll add another 1; that's loop 3 add another 1 up to 10.
 
|Okay I'll say loop 1 and add 1 and then I'll say loop 2 and I'll add another 1; that's loop 3 add another 1 up to 10.
  
 
|-
 
|-
|3:49
+
|03:49
 
|Lets open this up.  Refresh it.  There you go.  You got loop 1,2,3 all the way up to 10 as you can see
 
|Lets open this up.  Refresh it.  There you go.  You got loop 1,2,3 all the way up to 10 as you can see
  
 
|-
 
|-
|3:58
+
|03:58
 
|Lets change this value here to 100.  Refresh that. You can see it has gone to hundred.  The bigger the number, the longer it will take to loop
 
|Lets change this value here to 100.  Refresh that. You can see it has gone to hundred.  The bigger the number, the longer it will take to loop
  
 
|-
 
|-
|4:08
+
|04:08
 
|Let's take 6000. Let's refresh that.  It's going to take a while. There you go - up to 6000.  So it's very efficient in this way
 
|Let's take 6000. Let's refresh that.  It's going to take a while. There you go - up to 6000.  So it's very efficient in this way
  
 
|-
 
|-
|4:20
+
|04:20
 
|You can try combining this with an 'array' to create a program that echoes out of the alphabet inside the 'array'
 
|You can try combining this with an 'array' to create a program that echoes out of the alphabet inside the 'array'
  
 
|-
 
|-
|4:27
+
|04:27
 
|You can use loops to echo out every single value of an array
 
|You can use loops to echo out every single value of an array
  
 
|-
 
|-
|4:32
+
|04:32
 
|Just give it a go.  I will probably do this in one my tutorial - not in the basics section though
 
|Just give it a go.  I will probably do this in one my tutorial - not in the basics section though
  
 
|-
 
|-
|4:40
+
|04:40
 
|However, this is the basics structure. What I also recommend you to do is create a variable here called 'max' and put your maximum value here
 
|However, this is the basics structure. What I also recommend you to do is create a variable here called 'max' and put your maximum value here
  
 
|-
 
|-
|4:53
+
|04:53
 
|This will do exactly the same thing.  It's just a lot more easy to read and you can declare all this here and this would be a reference to it
 
|This will do exactly the same thing.  It's just a lot more easy to read and you can declare all this here and this would be a reference to it
  
 
|-
 
|-
|5:03
+
|05:03
 
|If you have more than 1 loop. I prefer it for readability and flexibility for my program.  Okay so that's a WHILE loop. Let me summarise. It checks the condition of the start
 
|If you have more than 1 loop. I prefer it for readability and flexibility for my program.  Okay so that's a WHILE loop. Let me summarise. It checks the condition of the start
  
 
|-
 
|-
|5:17
+
|05:17
 
|If the condition is True. it would execute this block of code and you can do things like 'echo alpha'
 
|If the condition is True. it would execute this block of code and you can do things like 'echo alpha'
  
 
|-
 
|-
|5:24
+
|05:24
 
|Your variable is being incremented. Make sure that you do increment your variable otherwise it will loop for infinity.
 
|Your variable is being incremented. Make sure that you do increment your variable otherwise it will loop for infinity.
  
 
|-
 
|-
|5:32
+
|05:32
 
|Thanks for watching.  This is Sidharth for the Spoken Tutorial Project, signing off.  Goodbye.
 
|Thanks for watching.  This is Sidharth for the Spoken Tutorial Project, signing off.  Goodbye.

Revision as of 11:15, 10 July 2014

Time Narration
00:00 Hello and welcome. I have decided to create seperate tutorials for each looping statement.
00:07 I want to keep it simple. This will be useful as a reference also if you need to refer to how a particular loop works.
00:17 In this tutorial, we will learn about the WHILE loop
00:21 A WHILE loop checks for a condition at the start at the loop and executes the code depending on whether this condition is True or not
00:38 for example I'll start my 'WHILE loop' here and this is the condition and this is my block.
00:51 I'll represent my block between curly brackets.
00:56 My condition is here. Now, in the 'IF statement', for example I used 1==1.
01:04 Now if I say 'test' or 'loop' here.
01:07 This is a loop here and then a break. Now what happens is as long as 1=1, it would create a loop
01:17 If I do something here, lets try this.
01:22 It would probably crash your browser because the loop would be repeated as long as 1=1 and for infinite no. of times, 1 will always equal 1.
01:34 So since the loop will always be repeated, your browser will crash.
01:40 Lets say while a variable, 'num' is smaller or equal to 10 and under echo i can say - 'num ++'
01:57 '++' is an arithmetical operator. And what it basically does is, it increases num by 1. It is the same as writing 'num =num +1'
02:16 So it takes num and says that it is equal to the value of num plus 1.
02:23 So this again is an arithmetical operator. What's going to happen is -
02:29 We are going to say 'num' lesser than or equal to '10', if yes then echo loop and then say add 1 on to the variable num
02:41 But what we should really do is create 'num = 1' at the moment. So loop once at 1. This will then equal 2 then 3 then 4 all the way up to 10 and then it will stop
03:01 After that the rest of the code below this will continue.
03:06 So we said this 1 and see what will we get. Okay we got a loop 1,2,3,4,5,6,7,8,9,10 times
03:20 Now to make it more fun I'll say loop 1 and I'll concatenate 'num' to the end of that
03:27 In fact let's make it simpler and say 'num' inside - it will make it much easier to read
03:37 Okay I'll say loop 1 and add 1 and then I'll say loop 2 and I'll add another 1; that's loop 3 add another 1 up to 10.
03:49 Lets open this up. Refresh it. There you go. You got loop 1,2,3 all the way up to 10 as you can see
03:58 Lets change this value here to 100. Refresh that. You can see it has gone to hundred. The bigger the number, the longer it will take to loop
04:08 Let's take 6000. Let's refresh that. It's going to take a while. There you go - up to 6000. So it's very efficient in this way
04:20 You can try combining this with an 'array' to create a program that echoes out of the alphabet inside the 'array'
04:27 You can use loops to echo out every single value of an array
04:32 Just give it a go. I will probably do this in one my tutorial - not in the basics section though
04:40 However, this is the basics structure. What I also recommend you to do is create a variable here called 'max' and put your maximum value here
04:53 This will do exactly the same thing. It's just a lot more easy to read and you can declare all this here and this would be a reference to it
05:03 If you have more than 1 loop. I prefer it for readability and flexibility for my program. Okay so that's a WHILE loop. Let me summarise. It checks the condition of the start
05:17 If the condition is True. it would execute this block of code and you can do things like 'echo alpha'
05:24 Your variable is being incremented. Make sure that you do increment your variable otherwise it will loop for infinity.
05:32 Thanks for watching. This is Sidharth for the Spoken Tutorial Project, signing off. Goodbye.

Contributors and Content Editors

Minal, PoojaMoolya, Pratik kamble, Sandhya.np14