PHP nested while loop -


i tried while inside while print multiplication table like,

1  2  3  4  5 2  4  6  8 10 3  6  9 12 15 4  8 12 16 20 5 10 15 20 25 

but got 1, 2, 3, 4, 5.

code:

$i = 1; $x = 1; while($i <= 5){    while($x <= 5){      echo $i * $x;      $x++;    }    echo "<br>";    $i++; } 

this happening because you're not resetting $x when inner loop completes iteration. try instead:

$i = 1; while($i <= 5) {   $x = 1;   while($x <= 5) {     echo $i * $x;     $x++;   }   echo "<br>";   $i++; } 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -