ayaya Posted December 28, 2012 Share Posted December 28, 2012 (edited) 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>"; } ?> Edited December 28, 2012 by ayaya Quote Link to comment https://forums.phpfreaks.com/topic/272450-php-newbies-question-someone-can-help-me-please/ Share on other sites More sharing options...
Christian F. Posted December 28, 2012 Share Posted December 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/272450-php-newbies-question-someone-can-help-me-please/#findComment-1401848 Share on other sites More sharing options...
ayaya Posted December 28, 2012 Author Share Posted December 28, 2012 Thank you very much! It works! Here is really a good place! thanks thanks a lot... Sorry, this is my first post, next time I'll know how to post code Quote Link to comment https://forums.phpfreaks.com/topic/272450-php-newbies-question-someone-can-help-me-please/#findComment-1401850 Share on other sites More sharing options...
drewdan Posted December 28, 2012 Share Posted December 28, 2012 Welcome to the forum, if your problem is solved, mark it as solved. Quote Link to comment https://forums.phpfreaks.com/topic/272450-php-newbies-question-someone-can-help-me-please/#findComment-1401854 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.