Is it good to use break and continue in PHP?

Is it good practice to use breakand continueas a checkpoint for loops in PHP?

eg

if (!empty($var))
    break;
+3
source share
8 answers
do {
 if (condition1)
   break;
 some code;
 some code;
 if (condition2)
   break;
 some code;
 some code;
 if (condition3)
   break;
 some code;
 some code;
} while (false);

against.

if (!condition1) {
   some code; 
   some code;
   if (!condition2) {
      some code;
      some code;
      if (!condition3) {
         some code;
         some code;
      }
}

. , . , , , , . , if (condition) break; - , if (condition) {some code; break}, do {if .. break; if .. break..;} while(false) ifs .

+4

, . break continue goto , .

+1

, .

, GOTO. (, , , !)

+1

break continue, . , .

while , break continue, , .

, break, , , - for foreach , - . break , , , . , .

, , switch break.

- , break n continue n, . ( , , ...)

+1

:

  • ?

  • ?

  • ?

0

Python , . , , .

0

PHP (, , ), - , , , n n.: -)

0

5+ PHP break switch.

Continue , .

GOTO?

,

if (!empty($var))
    break;

return ( )

if (!empty($var))
    return false;

I think this way is very clear and makes the caller know what happened inside. It is better to use errors for arguments, using Excecptions, which will actually interrupt the execution of a, in which they are raised.

0
source

Source: https://habr.com/ru/post/1733989/


All Articles