<?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-Do-While-Statement%2FEnglish</id>
		<title>PHP-and-MySQL/C2/Loops-Do-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-Do-While-Statement%2FEnglish"/>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Loops-Do-While-Statement/English&amp;action=history"/>
		<updated>2026-04-08T18:41:10Z</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-Do-While-Statement/English&amp;diff=536&amp;oldid=prev</id>
		<title>Chandrika: Created page with '{| border=1 !Time !Narration |- |00:00 |Welcome again!  In this tutorial, we will learn the DO-WHILE loop. |- |00:04 |Its also called the DO-WHILE  statement.  You can choose to …'</title>
		<link rel="alternate" type="text/html" href="https://script.spoken-tutorial.org/index.php?title=PHP-and-MySQL/C2/Loops-Do-While-Statement/English&amp;diff=536&amp;oldid=prev"/>
				<updated>2012-11-29T06:35:48Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;{| border=1 !Time !Narration |- |00:00 |Welcome again!  In this tutorial, we will learn the DO-WHILE loop. |- |00:04 |Its also called the DO-WHILE  statement.  You can choose to …&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;
|00:00&lt;br /&gt;
|Welcome again!  In this tutorial, we will learn the DO-WHILE loop.&lt;br /&gt;
|-&lt;br /&gt;
|00:04&lt;br /&gt;
|Its also called the DO-WHILE  statement.  You can choose to call it a loop or a statement.&lt;br /&gt;
|-&lt;br /&gt;
|00:11&lt;br /&gt;
|The base is similar to the WHILE loop, although the condition is checked at the END of the loop as opposed to the START.&lt;br /&gt;
|-&lt;br /&gt;
|00:20&lt;br /&gt;
|We have DO, our block with the curly brackets, and WHILE  at the end.  Then a condition in here.  So this is the condition.&lt;br /&gt;
|-&lt;br /&gt;
|00:29&lt;br /&gt;
|Now I'm going to type a little program - I want the numbers to increment each time and echo on each line as I've done in my WHILE loop.&lt;br /&gt;
|-&lt;br /&gt;
|00:44&lt;br /&gt;
|Now the condition - when the number reaches 10, I want a variable called name, to be changed to another name in which the loop will stop.&lt;br /&gt;
|-&lt;br /&gt;
|00:59&lt;br /&gt;
|I'll type num = 1 to start with.&lt;br /&gt;
|-&lt;br /&gt;
|01:04&lt;br /&gt;
|Then I'll type my name is Alex.&lt;br /&gt;
|-&lt;br /&gt;
|01:09&lt;br /&gt;
|The condition of the loop I want is - while the name = Alex.&lt;br /&gt;
|-&lt;br /&gt;
|01:17&lt;br /&gt;
|As long as the name=Alex this will loop.  So somewhere we need to say on a specific condition - change the name to Billy and then the loop won't continue any more because the name is not equal to Alex.&lt;br /&gt;
|-&lt;br /&gt;
|01:31&lt;br /&gt;
|Now, we will include an IF statement inside the DO loop. Remember you can put &lt;br /&gt;
*  IF statements inside IF statements&lt;br /&gt;
*  IF statements inside loops&lt;br /&gt;
*  loops inside loops &lt;br /&gt;
and there's really no limit to what you do.  As long as your code works and flows properly and doesn't produce infinite values, you will be fine.&lt;br /&gt;
|-&lt;br /&gt;
|01:52&lt;br /&gt;
|Now what we type is DO.&lt;br /&gt;
|-&lt;br /&gt;
|01:55&lt;br /&gt;
|Firstly, echo out the value of the number.&lt;br /&gt;
|-&lt;br /&gt;
|01:58&lt;br /&gt;
|You can concatenate that with a brief HTML code to break the line.&lt;br /&gt;
|-&lt;br /&gt;
|02:03&lt;br /&gt;
|Here I type num++ which is the same as num +1&lt;br /&gt;
|-&lt;br /&gt;
|02:14&lt;br /&gt;
|Then my IF statement - If num is greater than or equal to 10 then no echo.&lt;br /&gt;
|-&lt;br /&gt;
|02:26&lt;br /&gt;
|I want to change the name to Billy.&lt;br /&gt;
|-&lt;br /&gt;
|02:34&lt;br /&gt;
|Let me recap.  Remember, I'm not using curly brackets here because I have one line of code that needs to be executed in the block after the IF statement&lt;br /&gt;
|-&lt;br /&gt;
|02:43&lt;br /&gt;
|Therefore I just need one line code because it looks neat.&lt;br /&gt;
|-&lt;br /&gt;
|02:50&lt;br /&gt;
|So, let me recap what I've done.  I've got the number set to 1.&lt;br /&gt;
|-&lt;br /&gt;
|02:53&lt;br /&gt;
|This is my number variable, this can increment and can be echoed out to the user.&lt;br /&gt;
|-&lt;br /&gt;
|02:56&lt;br /&gt;
|I've got my name set to Alex.&lt;br /&gt;
|-&lt;br /&gt;
|03:00&lt;br /&gt;
|We start our DO.&lt;br /&gt;
|-&lt;br /&gt;
|03:02&lt;br /&gt;
|The name is still Alex.&lt;br /&gt;
|-&lt;br /&gt;
|03:04&lt;br /&gt;
|There's no condition so this will run regardless of anything&lt;br /&gt;
|-&lt;br /&gt;
|03;07&lt;br /&gt;
|So we echo out the number which is 1&lt;br /&gt;
|-&lt;br /&gt;
|03:09&lt;br /&gt;
|We increment it by 1 which will equal 2&lt;br /&gt;
|-&lt;br /&gt;
|03:12&lt;br /&gt;
|Now, we'll say if the number which is currently 2 is bigger than or equal to 10, (which it isn't) then  continue through this&lt;br /&gt;
|-&lt;br /&gt;
|03:26&lt;br /&gt;
|It isn't. So skip this.  It'll go on to say name = Alex.  And then go back to the top.&lt;br /&gt;
|-&lt;br /&gt;
|03:33&lt;br /&gt;
|This will still be 2.That means the loop's stuck at that block of code.&lt;br /&gt;
|-&lt;br /&gt;
|03:41&lt;br /&gt;
|It'll echo out 2&lt;br /&gt;
|-&lt;br /&gt;
|03:43&lt;br /&gt;
|It'll add one and say 3&lt;br /&gt;
|-&lt;br /&gt;
|03:46&lt;br /&gt;
|And then it'll say, is 3 bigger than or equal to 10.&lt;br /&gt;
|-&lt;br /&gt;
|03:51&lt;br /&gt;
|Now, it's not.&lt;br /&gt;
|-&lt;br /&gt;
|03:52&lt;br /&gt;
|So, the name is not changed to Billy instead it'll carry on with the rest of our code.&lt;br /&gt;
|-&lt;br /&gt;
|03:56&lt;br /&gt;
|The name's still Alex&lt;br /&gt;
|-&lt;br /&gt;
|03:58&lt;br /&gt;
|So, the loop continues on. In this case it will go on until it reaches 10, but 9 will be echoed out to the user&lt;br /&gt;
|-&lt;br /&gt;
|04:07&lt;br /&gt;
|Now num will become 10&lt;br /&gt;
|-&lt;br /&gt;
|04:09&lt;br /&gt;
|The IF condition will be True.&lt;br /&gt;
|-&lt;br /&gt;
|04:11&lt;br /&gt;
|The name would be set to Billy and in the while condition it doesn't equal Alex.So the WHILE loop will stop and the code down here will continue.&lt;br /&gt;
|-&lt;br /&gt;
|04:28&lt;br /&gt;
|So lets execute this code. Do our loop.  Click on that.&lt;br /&gt;
|-&lt;br /&gt;
|04:31&lt;br /&gt;
|OK, we've got 1 2 3 all the way up to 9.&lt;br /&gt;
|-&lt;br /&gt;
|04:35&lt;br /&gt;
|Obviously, our condition has been met. Our name has changed to Billy.  Our name doesn't equal Alex anymore.&lt;br /&gt;
|-&lt;br /&gt;
|04:41&lt;br /&gt;
|So, our loop here has stopped.   &lt;br /&gt;
|-&lt;br /&gt;
|04:44&lt;br /&gt;
|Now change the IF to 11 or you can change num to 0&lt;br /&gt;
|-&lt;br /&gt;
|04:50&lt;br /&gt;
|Now this won't work and you'll see why &lt;br /&gt;
|-&lt;br /&gt;
|04:54&lt;br /&gt;
|We've got 0 to 9&lt;br /&gt;
|-&lt;br /&gt;
|04:57&lt;br /&gt;
|The reason being is your starting number&lt;br /&gt;
|-&lt;br /&gt;
|05:02&lt;br /&gt;
|What this will do is, like I said before, it'll echo out the current number, then change it to an increment of 1 and then it'll compare it in the IF statement.&lt;br /&gt;
|-&lt;br /&gt;
|05:11&lt;br /&gt;
|So, you're comparing what you can't see.&lt;br /&gt;
|-&lt;br /&gt;
|05:13&lt;br /&gt;
|If you change this to 11, you'll compare it to 11, then change it to Billy and then it'll end the loop.&lt;br /&gt;
|-&lt;br /&gt;
|05:20&lt;br /&gt;
|We never see the value of 11, it's only an inside comparison.&lt;br /&gt;
|-&lt;br /&gt;
|05:26&lt;br /&gt;
|If we refresh this,  we can see there's 1 to 10 now.&lt;br /&gt;
|-&lt;br /&gt;
|05:30&lt;br /&gt;
|That is basically the DO-WHILE loop.  Even though they are pretty similar,the Do-WHILE loop is more useful than the WHILE loop when you run into a programming sort of logic.  It may be more useful in some cases.&lt;br /&gt;
|-&lt;br /&gt;
|05:44&lt;br /&gt;
|So, practice this, try and enter some values.  Also, try to recreate the program I've just created.&lt;br /&gt;
|-&lt;br /&gt;
|05:50&lt;br /&gt;
|There will be more tutorials on loops shortly   So keep watching.&lt;br /&gt;
|-&lt;br /&gt;
|05:56&lt;br /&gt;
|This is Anoushka dubbing for the Spoken Tutorial Project.&lt;/div&gt;</summary>
		<author><name>Chandrika</name></author>	</entry>

	</feed>