⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 control-structures.while.html

📁 php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head>  <title>while</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.alternative-syntax.html">Alternative syntax for control structures</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.do.while.html">do-while</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.while" class="sect1">   <h2 class="title"><i>while</i></h2>   <p class="para">    <i>while</i> loops are the simplest type of loop in    PHP.  They behave just like their C counterparts.  The basic form    of a <i>while</i> statement is:    <div class="informalexample">     <div class="example-contents"><div class="cdata"><pre>while (expr)    statement</pre></div>     </div>    </div>   </p>   <p class="simpara">    The meaning of a <i>while</i> statement is simple.  It    tells PHP to execute the nested statement(s) repeatedly, as long    as the <i>while</i> expression evaluates to    <b><tt>TRUE</tt></b>.  The value of the expression is checked    each time at the beginning of the loop, so even if this value    changes during the execution of the nested statement(s), execution    will not stop until the end of the iteration (each time PHP runs    the statements in the loop is one iteration).  Sometimes, if the    <i>while</i> expression evaluates to    <b><tt>FALSE</tt></b> from the very beginning, the nested    statement(s) won&#039;t even be run once.   </p>   <p class="para">    Like with the <i>if</i> statement, you can group    multiple statements within the same <i>while</i> loop    by surrounding a group of statements with curly braces, or by    using the alternate syntax:    <div class="informalexample">     <div class="example-contents"><div class="cdata"><pre>while (expr):    statement    ...endwhile;</pre></div>     </div>    </div>   </p>   <p class="para">    The following examples are identical, and both print the numbers     1 through 10:    <div class="informalexample">     <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;example&nbsp;1&nbsp;*/<br /><br /></span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />while&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;=&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++;&nbsp;&nbsp;</span><span style="color: #FF8000">/*&nbsp;the&nbsp;printed&nbsp;value&nbsp;would&nbsp;be<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$i&nbsp;before&nbsp;the&nbsp;increment<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(post-increment)&nbsp;*/<br /></span><span style="color: #007700">}<br /><br /></span><span style="color: #FF8000">/*&nbsp;example&nbsp;2&nbsp;*/<br /><br /></span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />while&nbsp;(</span><span style="color: #0000BB">$i&nbsp;</span><span style="color: #007700">&lt;=&nbsp;</span><span style="color: #0000BB">10</span><span style="color: #007700">):<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$i</span><span style="color: #007700">++;<br />endwhile;<br /></span><span style="color: #0000BB">?&gt;</span></span></code></div>     </div>    </div>   </p>  </div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="control-structures.alternative-syntax.html">Alternative syntax for control structures</a></div> <div class="next" style="text-align: right; float: right;"><a href="control-structures.do.while.html">do-while</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 + -