| PHP Tutorial | PHP Resources | PHP Server | |
As you grow to a better coder, you will often met a situation where you have to execute a block of code several times in order to get a result. This is where looping is useful of! The 'For' statement allows you to create loop that automatically execute desired blocks of code as many times as you like. To illustrate this, let say you want to create 100 lines of words. Instead of writting it one by one, you can ask PHP to do this for you. Fast and easy! <?php
The 'for' statement consist of three expressions.
?>
There are several way to loop in PHP. The second method is to use while statement. It acts exactly like 'For' but only it allows you to create a condition. Thus, when condition returns to true, it will start the looping. Take the example above. Let say you are going to print out 100 words of text. <?php
?> In this example, PHP will first assign 0 to variable $x. And then it will check whether the condition is true. What we want to do here is to ask PHP to print out the word 'welcome' as much as 100 times. Thus, when PHP read this line while($x <= 100) , it return to true because the number 0 is smaller than 100. So, the looping begin. This process continues until the condition return false. When will it return false? The third looping method is 'foreach'. This is commonly used to print out the value of an array. I will talk about this when you have understand what is an array and how to loop it. |
Optimize Website - Webmasters optimize their site and gain higher search engine ranking Webmaster tools - Free online webmaster toolkits, website reporting and free PHP opensource scripts. Free Photo Hosting - Free File Hosting, Free ZIP file Hosting, Free Image Hosting, Free MP3 Hosting. Stupid Videos - Custom Pimped Motorcycle Pictures, Videos, and Articles Planet Diaz - Programming Community - Online programming resource for programmers all around the world Forectory - Webmaster Directory St Louis Computer NetworkingWebsite Templates - 1000s of Templates $5 - Many Templates to help you build your site!
|
Each and every tutorial published in PHPhelps.com
is originally written by PHPHELPS OWNERS. None of the content is allowed
to be replicated without prior notice to writter. Copyright © 2006 PHPhelps.com |