Home Tutorials IT Jobs Source Codes Certifications Discussion Forum
  PHP Tutorials
PHP Introduction
PHP Installation
Syntax
Variables
Echo
Strings
Operators
Comments
Require
Include
If...Else
Switch
Forms
Functions
Arrays
While Loop
For Loop
For Each
Do While
Post & Get
File Create
File Open
File Close
File Write / Read
File Delete
File Append
File Truncate
File upload
PHP str replace
PHP substr_replace
PHP Capitalization
PHP Explode
PHP Implode
   IT Jobs
Software Jobs
Networking Jobs
   Model Question Papers
BE Computer Science
MCA
BCA
Others
 
   

PHP - while loop

In PHP there are several different types of loops. Basically what a loop does is evaluate a statement as true or false. If it is true it executes some code and then alters the original statement and starts all over again by re-evaluating it. It continues to loop through the code like this until the statement becomes false.


Basically what this does is: while a number is greater than or equal to 10 it prints the number. The ++ adds one to the number, however this could also be phrased as $num = $num + 1; Once the number becomes greater than 10, in our case it becomes 11, then it stops executing the code within the {brackets}

Below is an example of how you can combine a loop with a conditional

<?php 
$num = 1; 
while ( $num <=10 ) 
{ 
if ($num < 5) 
{ 
print $num . " is less than 5 <br>"; 
} 
else 
{ 
print $num . " is not less than 5 <br>"; 
} 
$num++; 
} 
?>

 

<< Previous | Next >>
Home  |  About us  | Privacy  |  Disclaimer  |  Contact us |  Advertise with us | Our Link Partners
All Rights Reserved 2009, CodeTeller.com