PHP While Tutorial online session | Coding Tag
×

PHP while / do..while / for loop / foreach

3679

In programming, it is often essential to replicate the same block of code a given number of times, or until a definite state is met.

This can be accomplished by using looping statements. PHP supports four major looping statements:

PHP have four looping types:

while - loop through a block of code if and as long as particular condition is true

do..while - loop through a block of code once, and then repeats the loop as long as the particular condition is true

for loop - loop through a block of code a specified number of times

foreach - loop through a block of code for each element in an array

while loop

while(condition is true)
{
code to be executed;
}

do..while loop

do
{
code to be executed;
}
while(condition is true);

for loop

for(initialization; condition; increment)
{
code to be executed;
}

foreach loop

foreach($array as $value)
{
code to be executed;
}



Best WordPress Hosting


Share:


Discount Coupons

Get a .COM for just $6.98

Secure Domain for a Mini Price



Leave a Reply


Comments
    Waiting for your comments