PHP
  Home arrow PHP arrow Page 6 - PHP Statements and Beginning Loops
The Best Selling PC Migration Utility.
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

PHP Statements and Beginning Loops
By: James Payne
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2007-11-05

    Table of Contents:
  • PHP Statements and Beginning Loops
  • If
  • Else
  • Elseif
  • Here We Go Loop de Loop
  • For Loop

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    PHP Statements and Beginning Loops - For Loop
    (Page 6 of 6 )

    Say you want to count to one million, but since you're too lazy, you decided to watch your computer do it instead. The For loop was designed specifically for slackers like you.


    <html>

    <body>


    <?php


    $count_for_me = 0;


    for ($i = 0; $i < 1,000,000; $i++)

    {

    $count_for_me += $count_for_me;

    }

    ?>


    </body>

    </html>

    I recommend changing the $count_for_me part to like 100 before running this program, otherwise you will be sitting there for a while.

    Breaking down the Code

    The For loop has three parts. The first part is the initializer, which initializes a counter variable. We set it to zero to execute the loop 1,000,000 times. If we set it to 1, it would only go through 999,000 times.

    The second part is the conditional part. This is the part where you give the program the criteria of how many times to run. It will keep running until this criteria is met. In this instance while $i is less than a million.

    The third and final part of the loop is the loop expression, which tells the program what action to take on the $i counter variable. In this case, we are incrementing it by one.

    Well folks, that's it for this tutorial. We will cover the rest of the loops in the next edition. Till then...


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.

       · Hey thanks for stopping by. In this article I discuss conditional statements like...
       · On page 3:There's the following...
       · I enjoy your writing style and the subject matter but there are a few...
     

       

    PHP ARTICLES

    - Setting Up a Web-based Image Hosting Service
    - Comparing Files and Databases with PHP Bench...
    - Setting Up a Web-Based Image Gallery
    - Using Timers to Benchmark PHP Applications
    - Benchmarking Applications with PHP
    - Setting Up a Web-Based File Manager: PHPfile...
    - Developing a Modular Class For a PHP File Up...
    - Setting Up a Web-Based File Manager: bfExplo...
    - Defining a Custom Function for File Uploader...
    - Parsing Child Nodes with the DOM XML extensi...
    - Creating an Error Handling Module for a PHP ...
    - Accessing Attributes and Cloning Nodes with ...
    - Retrieving Information on Selected Files wit...
    - Handling HTML Strings and Files with the DOM...
    - Building File Uploaders with PHP 5

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway