1

I won't break a loop that is in another loop these are my codes

                for ($i = 0; $i < 20; $i++) {
//                some codes
                for ($i1 = 0; $i1 < 10; $i1++) {
                    if (a condition)
                    {
//                        i want break this loop not parent loop
                    }
                }
                //                some codes

            }

if I use break; parent loop will break too but I won't break only work for child loop thanks for your answers

Mahdi mehrabi
  • 1,486
  • 2
  • 18
  • 21
  • `break` will only exit one level, if the outer loop is exiting then there is something else which we can't see going on. – Nigel Ren Dec 08 '18 at 07:03

2 Answers2

0

break only breaks out of the loop it's called in. If you want to break out of an outer control structure, you can use the optional integer argument to tell break the number of structures it should break out of (e.g., in this case, break 2 would break out of the outer loop).

Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

I used this and its worked

             for ($i = 0; $i < 20; $i++) {
//                some codes
                for ($i1 = 0; $i1 < 10; $i1++) {
                    if (a condition)
                    {
                          $i1=11;
                    }
                }
                //                some codes

            }
Mahdi mehrabi
  • 1,486
  • 2
  • 18
  • 21