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 Pakainfo.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!.

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:

Read Also:  How to upload image in codeigniter mysql database and display?

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


The break statement :

PHP Loop Example:

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

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 pakainfo is A Red CD.
Welcome to pakainfo is A Red Apple.
Welcome to pakainfo is A Red Plum.
Welcome to pakainfo is A blue CD.
Welcome to pakainfo is A blue Apple.
Welcome to pakainfo is A blue Plum.
Welcome to pakainfo is A black CD.
Welcome to pakainfo is A black Apple.
Welcome to pakainfo is A black Plum.


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 $pakainfo , $data;
for( $pakainfo=1; $pakainfo<3; $pakainfo++ )
{
   for( $data=1; $data<3; $data++
   {
      echo ‘i am devloper  ‘;
   }
   echo ‘<br />’;
}
?>

Program – Output:

Read Also:  how to convert char array to string in Java? | char array to string

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 $pakainfo=1 , $data=2;
do
{
   do
   {
      echo ‘i am devloper  ‘;
      $data++;
   }while( $data < 3 )
   echo ‘<br />’;
   $pakainfo++;
}while( $pakainfo < 3 )
?>

Program – Output:

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 $pakainfo = 1 , $data = 1;
while( $pakainfo < 3 )
{
    while( $data < 3 )
    {
        echo ‘i am devloper  ‘;
        $data++;
    }
    echo ‘<br />’;
    $pakainfo++;
}
?>

Program – Output:

Read Also:  Form Input Fields Validation using Angular Example

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

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(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.