Jump to content

Keep Looping Until True


papaface

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/179840-keep-looping-until-true/
Share on other sites

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.