almightyegg Posted September 6, 2007 Share Posted September 6, 2007 I need to echo out the same line of code out (well almost the same) a certain amount of times... I tried this but it didn't work $i = 1; while(($i == $lvlgain)){ $i = $i+1; $ghgh = $i+$mem[level]; echo "Congratulations! You are now level $ghgh and you gained 5 allocation points.<br>"; } I hope you can see what I'm trying to do...if not I can attempt to explain in detail Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/ Share on other sites More sharing options...
GingerRobot Posted September 6, 2007 Share Posted September 6, 2007 Well, you have an infinite loop there. If $i equals $lvlgain to start with, then the loop will never end because you make no change to the $lvlgain variable inside the loop. If they aren't equal, then the loop will never run anyway. I cant really suggest what to change as i've no idea what you are trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343103 Share on other sites More sharing options...
lemmin Posted September 6, 2007 Share Posted September 6, 2007 Actually, if they start out the same, it will run once because $i is incremented. You might want to use a greater than or less than operator. Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343105 Share on other sites More sharing options...
jvrothjr Posted September 6, 2007 Share Posted September 6, 2007 for ($i=1; $i <= $loopCnt; $i++) { $ghgh = $i+$mem[level]; echo "Congratulations! You are now level $ghgh and you gained 5 allocation points.<br>"; } $loopCnt being the number of time you wish to echo the statement Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343106 Share on other sites More sharing options...
almightyegg Posted September 6, 2007 Author Share Posted September 6, 2007 I want it to while until $i equals $lvlgain.... does it make more sense now? Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343107 Share on other sites More sharing options...
jvrothjr Posted September 6, 2007 Share Posted September 6, 2007 while(($i <> $lvlgain)){ Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343110 Share on other sites More sharing options...
almightyegg Posted September 6, 2007 Author Share Posted September 6, 2007 Congratulations! You are now level 2 and you gained 5 allocation points. Congratulations! You are now level 3 and you gained 5 allocation points. Congratulations! You are now level 4 and you gained 5 allocation points. Congratulations! You are now level 5 and you gained 5 allocation points. Congratulations! You are now level 6 and you gained 5 allocation points. Congratulations! You are now level 7 and you gained 5 allocation points. Congratulations! You are now level 8 and you gained 5 allocation points. Congratulations! You are now level 9 and you gained 5 allocation points. Wonderful! Great thanks Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343115 Share on other sites More sharing options...
GingerRobot Posted September 6, 2007 Share Posted September 6, 2007 Actually, if they start out the same, it will run once because $i is incremented. You might want to use a greater than or less than operator. Whoops. Indeed your right. Not quite sure what i was thinking! Quote Link to comment https://forums.phpfreaks.com/topic/68251-solved-more-while-help/#findComment-343118 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.