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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.