markvaughn2006 Posted October 13, 2009 Share Posted October 13, 2009 I'm sure this is childsplay but it is stumping me, everytime i try what I think would make this work, the page hangs... what am i doing wrong here?? <?php $number = 5; ?> <?php while ($number < 10){ $number = $number + 1} ?> <?php echo $number //hoping for it to be 10 ?> before you ask, i'm trying to figure out the principal to make this work, I'm not actually trying to make a number less than 10 become 10, but I need to know how to make this work to do some things. Thanks!! Quote Link to comment https://forums.phpfreaks.com/topic/177576-do-whilewoes/ Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 what exactly is the problem? when I run the following $i = 0; while ($i < 10){ $i++; } echo $i; it echos 10. what don't you understand? how the loop works? why it equals 10? Quote Link to comment https://forums.phpfreaks.com/topic/177576-do-whilewoes/#findComment-936281 Share on other sites More sharing options...
markvaughn2006 Posted October 13, 2009 Author Share Posted October 13, 2009 i guess the problem i'm having is actually because its a two part loop....i'm trying to recreate this from memory,(at school atm..) i think i'm approaching this problem the wrong way too... I'm making a game, where you get energy every x minutes...so.. if you use up all your energy and then don't sign back in till like a week later or something it will check your refill time to see if it is less than time(), if it is then it will add 3600 to your refill time and give you 10 energy, but the refill time will still be less than time() so it needs to keep checking if refill time < time() and while it is add 3600 to refill time && add 10 to energy...the way i have it set up now, it doesn't loop so really in this situation everytime you refresh it will add 10 to your energy and add an hour to your refill time until either max energy or refill time> time()... but when i tried to do the while loop for this, the page would just go white, and look like it got stuck... any idea? maybe there is a smarter way to do this?? thanks for helping!! i'll post more specific if still not solved when i get home Quote Link to comment https://forums.phpfreaks.com/topic/177576-do-whilewoes/#findComment-936289 Share on other sites More sharing options...
mikesta707 Posted October 13, 2009 Share Posted October 13, 2009 seems like you got an infinite loop. without seeing the code I can't be of much help. it sounds fine in theory, but it depends on how well (or how correctly) you implemented this. Quote Link to comment https://forums.phpfreaks.com/topic/177576-do-whilewoes/#findComment-936292 Share on other sites More sharing options...
knsito Posted October 13, 2009 Share Posted October 13, 2009 semicolons are needed.... You have error reporting turned off I take it.. Quote Link to comment https://forums.phpfreaks.com/topic/177576-do-whilewoes/#findComment-936302 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.