Php Nested Loops – while foreach do-while continue break statement

Php Nested Loops – while foreach do-while continue break statement

In this Post We Will Explain About is Php Nested Loops – while foreach do-while continue break statement With Example and Demo.Welcome on Live24u.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to php – Nested Loop, Break Inner Loops and Continue The Main LoopExample

In this post we will show you Best way to implement How to Break the nested loop in PHP, hear for Continue and Break Statement in PHPwith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

You can download source code and Demo from below link.




Also Read :   AngularJS Form Validation

The continue statement:

PHP Loop Example

<?php
$array = array( 1, 2, 3, 4, 5);
foreach( $array as $value )
{
   if( $value == 3 )continue;
   echo “Value is $value <br />”;
}
?>

Program – Output:

Value is 1
Value is 2
Value is 4
Value is 5


The break statement :

PHP Loop Example:

<?php
$live = 0;
while( $live < 5)
{
   $live++;
   if( $live == 2 )break;
}
echo (“Live 24 u Loop stopped at i = $live" );
?>

Program – Output:

Live 24 u Loop stopped at i = 2


Nested Foreach loop in php :

Syntax:

foreach(array as value)
{
   foreach(array as value)
   {
      Statement;
   }
   Statement;
}

PHP Loop Example:
<?php
$color= array( “Red”, "blue", "black", );
$fruit = array( "CD", “Apple”, “Plum”, );
foreach ($color as $c)
{
   foreach ($fruit as $f)
   {
      echo “this is A $c $f .<br/>\n”;
   }
}
?>

Program – Output:

Welcome to live24u is A Red CD.
Welcome to live24u is A Red Apple.
Welcome to live24u is A Red Plum.
Welcome to live24u is A blue CD.
Welcome to live24u is A blue Apple.
Welcome to live24u is A blue Plum.
Welcome to live24u is A black CD.
Welcome to live24u is A black Apple.
Welcome to live24u is A black Plum.

Also Read :   Autocomplete textbox using jQuery PHP and MySQL

Nested for loop in php :

Syntax:

for ( initialization; your_condition; incdata/decdata )
{
   for ( initialization; your_condition; incdata/decdata )
   {
      statement(s);
   }
   statement(s);
}

PHP Loop Example:

<?php
int $live , $data;
for( $live=1; $live<3; $live++ )
{
   for( $data=1; $data<3; $data++
   {
      echo ‘i am devloper  ‘;
   }
   echo ‘<br />’;
}
?>

Program – Output:

i am devloper i am devloper
i am devloper i am devloper


Nested do while loop in php :

Syntax:

do
{
   statement(s);
   incdata/decdata;
   do
   {
      statement(s);
      incdata/decdata;
   }while( your_condition );
}while( your_condition );

PHP Loop Example:

<?php
int $live=1 , $data=2;
do
{
   do
   {
      echo ‘i am devloper  ‘;
      $data++;
   }while( $data < 3 )
   echo ‘<br />’;
   $live++;
}while( $live < 3 )
?>

Program – Output:

Also Read :   Ajax PHP MySQL Creating Autocomplete Search Suggestion

i am devloper i am devloper
i am devloper i am devloper


Nested while loop in php :

Syntax :

while(your_condition)
{
    while(your_condition)
     {
        statement(s);
        incdata/decdata;
     }
    statement(s);
    incdata/decdata;
}

PHP Loop Example:

<?php
int $live = 1 , $data = 1;
while( $live < 3 )
{
    while( $data < 3 )
    {
        echo ‘i am devloper  ‘;
        $data++;
    }
    echo ‘<br />’;
    $live++;
}
?>

Program – Output:

i am devloper i am devloper
i am devloper i am devloper

You can download source code and Demo from below link.





Example

I hope you have Got What is php – Nested Loop, Break Inner Loops and Continue The Main Loop And how it works.I would Like to have FeadBack From My Blog(live24u.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(live24u.com) Are Most Always Welcome.

   

Add a Comment

Your email address will not be published.