0

Hello i was wondering on how can i get out of while loop while continuing the for loop, basically there is a while inside a while that's inside of a for loop.

<?php
for($i=1; $i <= counter($counter);$i++){
    while(){
        while(){
            if(){
               while(){
                  //if condition was met and successfully processed i want to go back to for loop. 
               }
            }else{
            }
        }
    }
}
?>
3
  • Your question hasn't explained enough regarding your requirements. Just let us know at what point you want to get out from those while loops, please share your efforts if you have gone through. Commented Aug 6, 2019 at 6:26
  • you can use break; for the purpose. In your case you need to use break 3; reference - php.net/manual/en/control-structures.break.php Commented Aug 6, 2019 at 6:53
  • i want to get out of the inner while loop and repeat for for loop with different value for variable $i Commented Aug 6, 2019 at 7:04

1 Answer 1

1

Use BREAK. You can also use BREAK 1 or 2 or 3 depends on how your loop nesting.

<?php
for($i=1; $i <= counter($counter);$i++){
    while(){
        while(){
            if(){
               while(){
                  //if condition was met and successfully processed i want to go back to for loop. 
                   break 3;
               }
            }else{
            }
        }
    }
}
?>
Sign up to request clarification or add additional context in comments.

3 Comments

it didn't work though it just stops after it met the condition inside while.
like i have said in the answer.. you can use Break 1 or Break 2 or Break 3. As per your goal, use Break 3.
you use break 3?

Your Answer

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