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>";

}

 

 

?>

Edited by ayaya
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.