runeveryday Posted September 19, 2010 Share Posted September 19, 2010 <?php for ($count = 0; $count < 10; $count++) { $randomNumber = rand(1,50); if ($randomNumber < 10) goto less; else echo "Number greater than 10: $randomNumber<br />"; } less: echo "Number less than 10: $randomNumber<br />"; ?> i checked this code again and again,but couldn't find any error. who can help me,thank you. Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/ Share on other sites More sharing options...
trq Posted September 19, 2010 Share Posted September 19, 2010 What results are you getting? Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1112724 Share on other sites More sharing options...
runeveryday Posted September 19, 2010 Author Share Posted September 19, 2010 it showed unexpected T_STRING .... Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1112749 Share on other sites More sharing options...
fortnox007 Posted September 19, 2010 Share Posted September 19, 2010 I am not sure if it's this, (i never worked with goto outside actionscript) I have the feeling you miss a {} after else <?php for ($count = 0; $count < 10; $count++) { $randomNumber = rand(1,50); if ($randomNumber < 10) goto less; }else{ echo "Number greater than 10: $randomNumber<br />"; } less: echo "Number less than 10: $randomNumber<br />"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1112755 Share on other sites More sharing options...
harristweed Posted September 19, 2010 Share Posted September 19, 2010 goto less; Will give an error, so will less: You were also missing some braces <?php for ($count = 0; $count < 10; $count++) { $randomNumber = rand(1,50); if ($randomNumber < 10){ //goto less; }else{ echo "Number greater than 10: $randomNumber<br />"; } //less: echo "Number less than 10: $randomNumber<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1112778 Share on other sites More sharing options...
trq Posted September 20, 2010 Share Posted September 20, 2010 What version of php are you using? GOTO requires 5.3* Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1113134 Share on other sites More sharing options...
PFMaBiSmAd Posted September 20, 2010 Share Posted September 20, 2010 OMG, the goto madness has started. DON'T use goto to make simple conditional logic complicated and hard to read and follow in your code - <?php for ($count = 0; $count < 10; $count++) { $randomNumber = rand(1,50); if ($randomNumber < 10) { echo "Number less than 10: $randomNumber<br />"; } else { echo "Number greater than or equal to 10: $randomNumber<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/213793-whats-wrong-with-the-code/#findComment-1113259 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.