📄 control-structures.continue.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>continue</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.break.html">break</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.switch.html">switch</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="control-structures.continue" class="sect1"> <h2 class="title"><i>continue</i></h2> <p class="simpara"> <i>continue</i> is used within looping structures to skip the rest of the current loop iteration and continue execution at the condition evaluation and then the beginning of the next iteration. </p> <blockquote><p><b class="note">Note</b>: <span class="simpara"> Note that in PHP the <a href="control-structures.switch.html" class="link">switch</a> statement is considered a looping structure for the purposes of <i>continue</i>. </span> </p></blockquote> <p class="simpara"> <i>continue</i> accepts an optional numeric argument which tells it how many levels of enclosing loops it should skip to the end of. </p> <p class="para"> <div class="informalexample"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /></span><span style="color: #007700">while (list(</span><span style="color: #0000BB">$key</span><span style="color: #007700">, </span><span style="color: #0000BB">$value</span><span style="color: #007700">) = </span><span style="color: #0000BB">each</span><span style="color: #007700">(</span><span style="color: #0000BB">$arr</span><span style="color: #007700">)) {<br /> if (!(</span><span style="color: #0000BB">$key </span><span style="color: #007700">% </span><span style="color: #0000BB">2</span><span style="color: #007700">)) { </span><span style="color: #FF8000">// skip odd members<br /> </span><span style="color: #007700">continue;<br /> }<br /> </span><span style="color: #0000BB">do_something_odd</span><span style="color: #007700">(</span><span style="color: #0000BB">$value</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />while (</span><span style="color: #0000BB">$i</span><span style="color: #007700">++ < </span><span style="color: #0000BB">5</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"Outer<br />\n"</span><span style="color: #007700">;<br /> while (</span><span style="color: #0000BB">1</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"&nbsp;&nbsp;Middle<br />\n"</span><span style="color: #007700">;<br /> while (</span><span style="color: #0000BB">1</span><span style="color: #007700">) {<br /> echo </span><span style="color: #DD0000">"&nbsp;&nbsp;Inner<br />\n"</span><span style="color: #007700">;<br /> continue </span><span style="color: #0000BB">3</span><span style="color: #007700">;<br /> }<br /> echo </span><span style="color: #DD0000">"This never gets output.<br />\n"</span><span style="color: #007700">;<br /> }<br /> echo </span><span style="color: #DD0000">"Neither does this.<br />\n"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> <p class="para"> Omitting the semicolon after <i>continue</i> can lead to confusion. Here's an example of what you shouldn't do. </p> <p class="para"> <div class="informalexample"> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /> </span><span style="color: #007700">for (</span><span style="color: #0000BB">$i </span><span style="color: #007700">= </span><span style="color: #0000BB">0</span><span style="color: #007700">; </span><span style="color: #0000BB">$i </span><span style="color: #007700">< </span><span style="color: #0000BB">5</span><span style="color: #007700">; ++</span><span style="color: #0000BB">$i</span><span style="color: #007700">) {<br /> if (</span><span style="color: #0000BB">$i </span><span style="color: #007700">== </span><span style="color: #0000BB">2</span><span style="color: #007700">)<br /> continue<br /> print </span><span style="color: #DD0000">"$i\n"</span><span style="color: #007700">;<br /> }<br /></span><span style="color: #0000BB">?></span></span></code></div> </div> <p class="para"> One can expect the result to be : </p> <div class="example-contents"><pre><div class="cdata"><pre>0134</pre></div> </pre></div> <p class="para"> but this script will output : </p> <div class="example-contents"><pre><div class="cdata"><pre>2</pre></div> </pre></div> <p class="para"> because the return value of the <a href="function.print.html" class="function">print()</a> call is <i>int(1)</i>, and it will look like the optional numeric argument mentioned above. </p> </div> </p> </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.break.html">break</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.switch.html">switch</a></div> <div class="up"><a href="language.control-structures.html">Control Structures</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -