papaface Posted November 1, 2009 Share Posted November 1, 2009 Hey, I am trying to create a loop based on a boolean output from a function. This is essentially what I have: function queue($skip) { if ($skip == false) { //some code which will check their queue status and return true if they're in the queue or false if they're not. } else return true; } Then: while (queue() == true) { //do something when they're in the queue } Is my code correct here? Will it not check the queue() function only once? Any help would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/179840-keep-looping-until-true/ Share on other sites More sharing options...
sKunKbad Posted November 1, 2009 Share Posted November 1, 2009 function queue($skip) { if($skip == FALSE) { // check for new skip value $new_skip = // some value from database or something queue($new_skip); } return TRUE; } Note that you have the potential for an infinite loop if skip never returns true. Quote Link to comment https://forums.phpfreaks.com/topic/179840-keep-looping-until-true/#findComment-948741 Share on other sites More sharing options...
Daniel0 Posted November 1, 2009 Share Posted November 1, 2009 "Keep looping until true" would pretty much be a while loop with a negated conditional statement because a while "keeps looping until false". Quote Link to comment https://forums.phpfreaks.com/topic/179840-keep-looping-until-true/#findComment-948742 Share on other sites More sharing options...
Alex Posted November 1, 2009 Share Posted November 1, 2009 To answer your question, no it will not check the queue function only once. It will check it each iteration. Quote Link to comment https://forums.phpfreaks.com/topic/179840-keep-looping-until-true/#findComment-948747 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.