Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online

control structures.for function syntax tag tutorial 2013 Donate at flattr Flattr this





Alert! Connect with 10,000 Chating Online. Join Now

Php control structures.for () function

Write your php code

 
<?php ?>

Php Result


Your code below



for

for loops are the most complex loops in PHP. They behave like their C counterparts. The syntax of a for loop is:

for (expr1; expr2; expr3)
    statement

The first expression (expr1) is evaluated (executed) once unconditionally at the beginning of the loop.

In the beginning of each iteration, expr2 is evaluated. If it evaluates to TRUE, the loop continues and the nested statement(s) are executed. If it evaluates to FALSE, the execution of the loop ends.

At the end of each iteration, expr3 is evaluated (executed).

Each of the expressions can be empty. expr2 being empty means the loop should be run indefinitely (PHP implicitly considers it as TRUE, like C). This may not be as useless as you might think, since often you'd want to end the loop using a conditional break statement instead of using the for truth expression.

Consider the following examples. All of them display numbers from 1 to 10:

<?php
/* example 1 */

for ($i = 1; $i <= 10; $i++) {
    echo
$i;
}

/* example 2 */

for ($i = 1; ; $i++) {
    if (
$i > 10) {
        break;
    }
    echo
$i;
}

/* example 3 */

$i = 1;
for (; ; ) {
    if (
$i > 10) {
        break;
    }
    echo
$i;
    
$i++;
}

/* example 4 */

for ($i = 1; $i <= 10; print $i, $i++);
?>

Of course, the first example appears to be the nicest one (or perhaps the fourth), but you may find that being able to use empty expressions in for loops comes in handy in many occasions.

PHP also supports the alternate "colon syntax" for for loops.

for (expr1; expr2; expr3):
    statement
    ...
endfor;

Php control structures.for Function syntax tag

control structures.for php code on this is provided for your study purpose, it will guide you to know how create and design a website using php. use it to practice and train your self online



Php control structures.for syntax tutorial

php tutorial guide and code design are for easy learning and programming. The code practice section provided at the top is for practising of this syntax. Use the code section up to practice your php programming online. Learning php is very easy, all you need is to use the examples on this site and practice them to perfect your skills.


Function index

Variables

Expressions

Operators

Control-Structures

Cookies

Array

Date & Time

Directory function

File

Image

Operators

Form data handling

Mathematics operators

Mail

Php Mysql

Network Functions

Strings

php tutorial guides,functions, classes, code examples and tags for creating simple dynamic site to mysql database driven sites
 
 
Htaccess    html   Php    javascript   Asp   css    maths  Past Questions  Practice Tests Online