Jump to content

Php Newbie's Question, Someone Can Help Me Please?


ayaya

Recommended Posts

Hello, I just start to learn PHP. I wrote this following code. But when I run, it enters in a dead loop, it continues running running, no end, and I must close Eclipse to end the code. Anyone can help me? What's the problem with my code?

Thanks in advance!

 

<?php

 

echo "<br>";

for($a=1;$a<=10;$a++){

for($b=1;$b>=$a;$b++){

if($a*$b<10){

$m="0".$a*$b;

echo $m;

}

echo "$b*$a=" . $a*$b . "\t";

}

echo "<br>";

}

for($c=9;$c>=1;$c--){

for($d=1;$d<=$c;$d++){

if($d*$c<10){

$n="0".$c*$d;

echo $n;

}

echo "$d*$c=" .$c*$d . "\t";

}

echo "<br>";

}

 

 

?>

The problem lies in this line:

for ($b = 1; $b >= $a; $b++) {

 

If you go through the code line by line, substituting the variables for their numbers, you should be able to spot the cause as well. ;)

 

PS: Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.