Is it good practice to use breakand continueas a checkpoint for loops in PHP?
break
continue
eg
if (!empty($var)) break;
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 .
if (condition) break;
if (condition) {some code; break}
do {if .. break; if .. break..;} while(false)
, . break continue goto , .
goto
, .
, GOTO. (, , , !)
break continue, . , .
while , break continue, , .
while
, break, , , - for foreach , - . break , , , . , .
for
foreach
, , switch break.
switch
- , break n continue n, . ( , , ...)
break n
continue n
:
?
Python , . , , .
PHP (, , ), - , , , n n.: -)
5+ PHP break switch.
Continue , .
GOTO?
,
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.
Source: https://habr.com/ru/post/1733989/More articles:How to iterate multiple drop-down lists and access their option values ββ- javascripttranslate javascript program into C - cΠΠ°ΡΠ°ΠΌΠ΅ΡΡΡ Π²ΡΠ±ΠΎΡΠ° JQuery - jqueryHow to get x and y for CGRect to initialize a control using a frame? - iphoneDownload cache overload database - asp.netMatch java core class with regex - javaIn SQL Server, what works best: where ProcessedDate is null or where Processed = 0 - performancejava string match issue - javaC89: getaddrinfo () on Windows? - cWhy do DIVs height contain images that are overpriced by 4.5px? - htmlAll Articles