SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2004
    Location
    england
    Posts
    114
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation keep calling function until it returns true?

    Hi

    I have a function which I call from a place within my script.
    In the function, I have a conditional statement and based on this it will have
    Code:
    return true;
    or
    Code:
    return false;
    but I want to get it to keep going through the function until it returns false.

    I tried this:
    Code:
    functioncall();
    while (!functioncall()) {
     functioncall();
    }
    can anyone give me any tips? cheers

  2. #2
    SitePoint Member
    Join Date
    Nov 2005
    Location
    Belgium
    Posts
    14
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Should work. Look at this example:
    PHP Code:
    function functioncall(){
      
    $rand mt_rand(010);
      if (
    $rand == 3){
        return 
    true;
      }
      echo 
    $rand.'<br />';
      return 
    false;
    }

    do{
     
    $return functioncall();
    }while (!
    $return); 
    It will echo the random number (btw 0 & 10) while not equal to 3.

    Edit: logical error.

  3. #3
    SitePoint Enthusiast Gonik's Avatar
    Join Date
    May 2005
    Location
    Thessaloniki, Greece
    Posts
    71
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?
    while(true) {
        if(
    functioncall() === true) break;
    }
    Don't Drink & Surf The Net

  4. #4
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    while(functioncall());


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •