Jump to content

What am I doing wrong?


canadian_angel

Recommended Posts

        <?php  // Script 6.2 - Odd Numbers

 

        // Address error handling.

        ini_set ('display_errors', 1);

        error_reporting (E_ALL & ~E_NOTICE);

 

        // Validate the Odd Numbers.

 

        /*  Odd Numbers */

 

        $i = 1;

      while ($i < 1 && => 49); {

        echo $i++;

 

// Print out odd numbers between 1-49.

for ($v <= 1; $v > 49; $v++)

print odd $v;

 

}

 

 

?>

Link to comment
https://forums.phpfreaks.com/topic/204798-what-am-i-doing-wrong/
Share on other sites

I think the better question to ask here is what are you doing right?  :shrug:

 

Assuming for the minute that the concept was correct your syntax for the following is incorrect.

 

$i < 1 && => 49

 

You have to do it like this:

 

$i < 1 && $i => 49

 

Addressing the logical problem, in your script $i will never be less than 1 (you set it to 1 right before this!). You also shouldn't have a semicolon after while(...) (see the manual on control structures.

 

Finally, you can't just do something like this:

 

print odd $v;

 

To solve your question to print out all odd numbers 0-49, you could take an approach like so:

 

for($i = 0;$i < 50;++$i) {
if($i % 2) {
	echo "$i is odd!<br />\n";
}
}

 

See arithmetic operators for more on the modulus operator.

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.