The break statement is used in the loop body or switch, which means to jump out of the current loop. If break appears in switch, it jumps out of the current switch statement body of switch. In the for loop, you jump out of the current loop. And continue is this loop, skip the statements after this loop and continue with the next loop.
Eg: 99 multiplication table
<code><span>for</span>(<span>$i</span>=<span>1</span>;<span>$i</span><<span>10</span>;<span>$i</span>++){ <span>for</span>(<span>$j</span>=<span>1</span>;<span>$j</span><=<span>$i</span>;<span>$j</span>++){ <span>if</span>(<span>$j</span>==<span>3</span>) <span>//会跳过j=3的算式</span><span>continue</span>; <span>echo</span><span>$i</span>.<span>'x'</span>.<span>$j</span>.<span>'='</span>.<span>$i</span>*<span>$j</span>.<span>' '</span>; } <span>echo</span><span>"<br/>"; }</code>
Pulse result: When j=3, this loop will end and the next loop will continue. The column i*3 will not appear
<code><span>for</span>(<span>$i</span>=<span>1</span>;<span>$i</span><<span>10</span>;<span>$i</span>++){ <span>for</span>(<span>$j</span>=<span>1</span>;<span>$j</span><=<span>$i</span>;<span>$j</span>++){ <span>if</span>(<span>$j</span>==<span>3</span>) <span>break</span>; <span>echo</span><span>$i</span>.<span>'x'</span>.<span>$j</span>.<span>'='</span>.<span>$i</span>*<span>$j</span>.<span>' '</span>; } <span>echo</span><span>"<br/>"; }</code>
Result: When the loop reaches j=3 , will jump out of this loop, i*3 and the following columns will not be executed, so only the two columns i*1 and i*2 will appear in the result
Copyright statement: This article is an original article by the blogger, and has not yet been published No reproduction is allowed without the permission of the blogger.
The above introduces the difference between break and continue in PHP, including the relevant content. I hope it will be helpful to friends who are interested in PHP tutorials.