0

I have a part in my code:

while($a = getrow()){
//code
}

getrow() is a function which keeps on returning array based on some condition.

what getrow() should return so that the while loop doesn't execute the code inside but takes the next value returned by getrow() function.

1
  • Please check my answer and see if it works for you and accept it if it does. Commented Jun 8, 2016 at 7:06

2 Answers 2

2

While loops will run as long as the condition remains true. So as long as you return rows, the code inside will get executed. If you return false, the while loop will terminate. If you want to conditionally avoid running code within the loop, your option is to return something like 'SKIP' and then inside the while loop check if $a == 'SKIP' and then issue a continue.

while($a = getrow()){
    if($a == 'SKIP')
        continue;
    //code
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can use continue control structure for skip an iteration. Please read the docs

 while($a = getrow()){
        if($a == 'something'){
            continue; // skip iteration
         }
        //rest code which you want to run
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.