canadian_angel Posted June 15, 2010 Share Posted June 15, 2010 <?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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/204798-what-am-i-doing-wrong/ Share on other sites More sharing options...
Alex Posted June 15, 2010 Share Posted June 15, 2010 I think the better question to ask here is what are you doing right? 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. Quote Link to comment https://forums.phpfreaks.com/topic/204798-what-am-i-doing-wrong/#findComment-1072187 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.