Question

I just started learning php and I have to do something like this which I got it working but I just have a few questions I want to ask for alternate way of doing but eh first of all the br/ is suppose to be with <> but somehow if i do that the coding at the bottom will see it as a line break.

Anyways if questions are...

  1. With the coding below the outcome will be 0-9 (without 5) but I have to set $zero=-1 if I put $zero=0 then the outcome would be 1-9 (without 5) is there a way I don't have to make $zero=-1 and still have the outcome of 0-9 (without 5)?

  2. I realized I have to put $zero++ before the if and continue statement if I put it at the end of the script after echo "$zero" . "br/"; the script won't run as wanted. Is this how it is suppose to be or I just don't know the other way of doing it.

Thanks in advance for people replying ^_^

$squared = pow(3,2);

echo "\"3 squared is $squared:";
echo "br/";

$zero = -1;
while ($squared > $zero)
{
    $zero++;
    if ($zero == 5)
    {
        continue;
    }
    else if ($squared == $zero)
    {
        echo "$squared\"";
    }
    else
    {
        echo "$zero" . "br/";
    }
}
Was it helpful?

Solution

Here it is (you were almost there :P )

$nr = 0;
while ($squared > $nr) {

    if (5 == $nr) {
        $nr++; // add this
        continue;
    } else if ($squared == $nr) {
        echo "$squared\"";
    } else {
        echo "$nr" . "<br/>";
    }
    $nr++; // move to the bottom
}

PS: You're welcome @clement

OTHER TIPS

Change your while loop to while ($squared >= $zero) and then set $zero = 0; Should work!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top