Bạn đang xem: Continue và break php
while ($foo) This would be used like so:
while ($droid = searchDroids()) if ($droid != $theDroidYoureLookingFor) continue; // ..the search with the next droid $foundDroidYoureLookingFor = true; break; // ..off the search
break exits the loop you are in, continue starts with the next cycle of the loop immediatly.
$i = 10;while (--$i) if ($i == 8) continue; if ($i == 5) break; eđến $i . " ";will output:
+1; just simple explanation và good example, even dough while(--$i) is a bit tricky for newbies. –user529649 Dec 6 "10 at 9:22
break ends execution of the current for, foreach, while, do-while or switch structure.
continue is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation và then the beginning of the next iteration.
So depending on your need, you can remix the position currently being executed in your code to a different màn chơi of the current nesting.
Also, see here for an artical detailing Break vs Continue with a number of examples
For the Record:
cảnh báo that in PHPhường the switch statement is considered a looping structure for the purposes of continue.
break used to get out from the loop statement, but continue just stop script on specific condition & then continue looping statement until reach the end..
for($i=0; $i"; continue; eđến $i . "";}eđến "";for($i=0; $i"; break; } emang lại $i . "";}Hope it can help u;
Break ends the current loop/control structure và skips to lớn the over of it, no matter how many more times the loop otherwise would have sầu repeated.
Xem thêm: Tải Game Aquarium Ios Miễn Phí, Pocket Aquarium! Cho Ios
Continue skips to lớn the beginning of the next iteration of the loop.
"continue" is used within looping structures to lớn skip the rest of the current loop iteration & continue execution at the condition evaluation and then the beginning of the next iteration.
"break" ends execution of the current for, foreach, while, do-while or switch structure.
break accepts an optional numeric argument which tells it how many nested enclosing structures are khổng lồ be broken out of.
Cheông chồng out the following links:
Hope it helps..
break will stop the current loop (or pass an integer to lớn tell it how many loops to lớn break from).
continue will stop the current iteration and start the next one.
Xem thêm: Thư Ứng Tuyển Top Cv - Hướng Dẫn Viết Cover Letter (Thư Xin Việc)
I am not writing anything same here. Just a changelog note from PHP. manual.
Changelog for continue
Version Description7.0.0 - continue outside of a loop or switch control structure is now detected at compile-time instead of run-time as before, & triggers an E_COMPILE_ERROR.5.4.0 continue 0; is no longer valid. In previous versions it was interpreted the same as continue 1;.5.4.0 Removed the ability to lớn pass in variables (e.g., $num = 2; continue $num;) as the numerical argument. Changelog for break
Version Description7.0.0 break outside of a loop or switch control structure is now detected at compile-time instead of run-time as before, and triggers an E_COMPILE_ERROR.5.4.0 break 0; is no longer valid. In previous versions it was interpreted the same as break 1;.5.4.0 Removed the ability to lớn pass in variables (e.g., $num = 2; break $num;) as the numerical argument.