<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="https://script.spoken-tutorial.org/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FLoops-While-Statement_%2FEnglish</id>
		<title>PHP-and-MySQL/C2/Loops-While-Statement /English - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://script.spoken-tutorial.org/index.php?action=history&amp;feed=atom&amp;title=PHP-and-MySQL%2FC2%2FLoops-While-Statement_%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Loops-While-Statement_/English&amp;action=history"/>
		<updated>2026-04-08T18:41:11Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.17</generator>

	<entry>
		<id>https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Loops-While-Statement_/English&amp;diff=534&amp;oldid=prev</id>
		<title>Chandrika: 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 b…'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Loops-While-Statement_/English&amp;diff=534&amp;oldid=prev"/>
				<updated>2012-11-29T06:34:43Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| 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 b…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{| border=1&lt;br /&gt;
!Time&lt;br /&gt;
!Narration&lt;br /&gt;
|-&lt;br /&gt;
|0:00&lt;br /&gt;
|Hello and welcome.  I have decided to create seperate tutorials for each looping statement.&lt;br /&gt;
|-&lt;br /&gt;
|0:07&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|0:22&lt;br /&gt;
|In this tutorial, we will learn about the WHILE loop&lt;br /&gt;
|-&lt;br /&gt;
|0:25&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|0:35&lt;br /&gt;
|for example I'll start my 'WHILE loop' here and this is the condition and this is my block&lt;br /&gt;
|-&lt;br /&gt;
|0:44&lt;br /&gt;
|I'll represent my block between curly brackets&lt;br /&gt;
|-&lt;br /&gt;
|0:52&lt;br /&gt;
|My condition is here.  Now, in the 'IF statement',  for example I used 1=1.&lt;br /&gt;
|-&lt;br /&gt;
|1:02&lt;br /&gt;
|Now if I say 'test' or 'loop' here.&lt;br /&gt;
|-&lt;br /&gt;
|1:08&lt;br /&gt;
|There is a loop here and then a break.  Now what happens is as long as 1=1, it would create a loop &lt;br /&gt;
|-&lt;br /&gt;
|1:14&lt;br /&gt;
|If I do something here, lets try this. &lt;br /&gt;
|-&lt;br /&gt;
|1:19&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|1:29&lt;br /&gt;
|So since the loop will always be repeated, your browser will crash&lt;br /&gt;
|-&lt;br /&gt;
|1:33&lt;br /&gt;
|Lets say while a variable, 'num' is smaller or equal to 10 and under echo i can say - 'num ++'&lt;br /&gt;
|-&lt;br /&gt;
|1:57&lt;br /&gt;
| '++' is an arithmetical operator. And what it basically does is, it increases num by 1.  It is the same as writing 'num =num +1'&lt;br /&gt;
|-&lt;br /&gt;
|2:16&lt;br /&gt;
|So it takes num and says that it is equal to the value of num plus 1.&lt;br /&gt;
|-&lt;br /&gt;
|2:22&lt;br /&gt;
|So this again is an arithmetical operator. What's going to happen is - &lt;br /&gt;
|-&lt;br /&gt;
|2:29&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|2:46&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|3:02&lt;br /&gt;
|After that the rest of the code below this will continue&lt;br /&gt;
|-&lt;br /&gt;
|3:06&lt;br /&gt;
|So we said this 1 and see what will we get. Okay we got a loop 1,2,3,4,5,6,7,8,10 times&lt;br /&gt;
|-&lt;br /&gt;
|3:20&lt;br /&gt;
|Now to make it more fun I'll say loop 1 and I'll concatenate 'num' to the end of that&lt;br /&gt;
|-&lt;br /&gt;
|3:29&lt;br /&gt;
|In fact let's make it simpler and say 'num' inside - it will make it easier to read&lt;br /&gt;
|-&lt;br /&gt;
|3:37&lt;br /&gt;
|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.&lt;br /&gt;
|-&lt;br /&gt;
|3:49&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|3:57&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|4:09&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|4:20&lt;br /&gt;
|You can try combining this with an 'array' to create a program that echoes out of the alphabet inside the 'array'&lt;br /&gt;
|-&lt;br /&gt;
|4:33&lt;br /&gt;
|You can use loops to echo out every single value of an array&lt;br /&gt;
|-&lt;br /&gt;
|4:36&lt;br /&gt;
|Just give it a go.  I will probably do this in one my tutorial - not in the basics section though&lt;br /&gt;
|-&lt;br /&gt;
|4:45&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|4:54&lt;br /&gt;
|It 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&lt;br /&gt;
|-&lt;br /&gt;
|5:02&lt;br /&gt;
|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&lt;br /&gt;
|-&lt;br /&gt;
|5:15&lt;br /&gt;
|If that condition is True. it would execute this block of code and you can do things like 'echo alpha'&lt;br /&gt;
|-&lt;br /&gt;
|5:21&lt;br /&gt;
|Your variable is being incremented. Make sure that you do increment your variable otherwise it will loop for infinity.&lt;br /&gt;
|-&lt;br /&gt;
|5:31&lt;br /&gt;
|Thanks for watching.  This is Sidharth for the Spoken Tutorial Project, signing off.  Goodbye.&lt;br /&gt;
|-&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>