PHP Tutorial





Español Français 中文 Deutsch Portuguese Japanese nederlands
   
 
PHP Topics
Introduction Introduction
Syntax Syntax
Data Types Data Types
Operators Operators
Control Structures Control Structures
Functions Functions
Pre-defined Function Pre-defined Function
Calendar Functions Calendar Functions
Date and Time Date and Time
Array Functions Array Functions
Array List Array Functions List1
Array Function List Array Functions List2
Math Functions Math Functions
PHP MYSQL Functions PHP Mysql Functions
File Handling File Handling
Error Handling Error Handling
DB Size DB Size
PHP Mail PHP Mail
String Tokens String Tokens
String Functions String Functions
String Functions List String Functions List1
String Functions List2 String Functions List2
Session Functions Session Functions
Cookies Functions Cookies Functions
Form Variables Form Variables
Running PHP from JS Running PHP from JS
Array To JS Array To JS
JS Array Array to PHP
Encryption Encryption
Common Header Common Header
Forums Ask Your Doubts
Scraps More about PHP
Feedback Feedback
 




PHP for Loop Structure


Tutorials »Php »

Topic

What is "for" loop Structure?



Explanation

For structure is a loop structure used in PHP, similar to that in C Language

Syntax
    for (initializtion;condition;increment)
    {Statements}//true

The "initializtion" is the initial value, "condition" is the condition value,"increment" is the increment or decrement value, every time based on the true value of "condition" the loop is executed, and at the end of every iteration it checks the value of "increment"

Example
    <?php
    for($c=0;$c=2;$c++)
    {
     echo "The value c is $c";
     break;
     }
    ?>

In the above example the value of $c is between 0 and 2, after every iteration of the loop the value of $c is increased by 1, then checked with the end values that is 2. If its less than 2, loop continues,else the loop ends

If the "expr2" does not have any value then a break statement can used to terminate the loop. See the example below

Example
    <?php
    for ($c = 1; ; $c++) {
    if ($c > 5) 
     {
        break;
     }
    echo $c;
    }
    ?>
Result:
    12345




A Note

Learn PHP programming language tutorial with simple and neat example. Hope you enjoy this free tutorial. Do give us your valuable feedback and suggestions on this online tutorial. This is a Copyright Content.

Other Links

web hosting