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

📄 day4_4.html

📁 这是帮助初学java的电子文档
💻 HTML
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312-80">
<style type="text/css">
<!--
a:link {  color: blue; text-decoration: none}
a:visited {  color: purple; text-decoration: none}
a:hover {  color: #CC0033; text-decoration: underline}
-->
</style>
<title>JavaScript教程</title>
</head>

<body topmargin="1" leftmargin="2">

<table border="0" width="591" cellspacing="0">
  <tr>
    <td bgcolor="#ffff99" width="451">JavaScript教程 - 第四课</td>
  </tr>
  <tr>
    <td bgcolor="#FF6600" width="451"><a href="mailto:thau@wired.com">Thau</a></td>
  </tr>
</table>
<div align="left">

<table border="0" width="630" cellspacing="0">
  <tr>
    <td width="458" valign="top" align="left"><strong><small><small><br>
    </small></small><font face="宋体" size="3">第四页:</font><font SIZE="3">再谈<font
    face="宋体">WHILE</font>循环</font></strong> <p><font SIZE="3">我们已见到了很多所请求的<font
    face="宋体">X`S</font>,现在复习一下:</font></p>
    <font SIZE="3"><p>第一步:请求<font face="宋体">X`S</font>的数目</p>
    </font><p><font face="宋体">var width = prompt(&quot;How many x's would you like? (1-10 
    is<br>
    good)&quot;,&quot;5&quot;);<br>
    </font></p>
    <p><font face="宋体" size="3">下一步,申报一些变量:</font> <ul>
      <pre><font face="宋体">
var a_line=&quot;&quot;;

var loop = 0;

</font></pre>
    </ul>
    <p><font face="宋体" size="3">现在,关键之处:</font> <ul>
      <pre><font face="宋体">

while (loop &lt; width)

{

	a_line = a_line + &quot;x&quot;;

	loop=loop+1;

}

</font></pre>
    </ul>
    <p><font face="宋体" size="3">即说:“当变量循环小于所请求的X`S行宽时,在该行加入另一<br>
    X然后在循环值上加1。”该循环将继续加一X到该行并在循环值<br>
    上加1直到循环不在小于请求的行宽。请看下列源码分析:</font> <dl>
      <dt><font face="宋体" size="3">第一次</font></dt>
      <dd><ul>
          <li><font face="宋体">a_line = &quot;&quot; (because we initialized it to be &quot;&quot;) 
            </font></li>
          <li><font face="宋体">loop=0 (because we initialized it to be 0) </font></li>
          <li><font face="宋体">width=2 (because that's what the user asked for) </font></li>
          <li><font face="宋体">0 is less than 2 so </font></li>
          <li><font face="宋体">a_line = a_line + &quot;x&quot;, so now a_line = &quot;x&quot; </font></li>
          <li><font face="宋体">loop=loop+1, so now loop = 1 </font></li>
        </ul>
      </dd>
      <dt><font face="宋体" size="3">返回循环:第二次</font></dt>
      <dd><ul>
          <li><font face="宋体">loop=1 </font></li>
          <li><font face="宋体">width=2 </font></li>
          <li><font face="宋体">a_line = &quot;x&quot; </font></li>
          <li><font face="宋体">1 is less than 2 so </font></li>
          <li><font face="宋体">a_line = a_line + &quot;x&quot;, so now a_line = &quot;xx&quot; </font></li>
          <li><font face="宋体">loop=loop+1, so now loop = 2 </font></li>
        </ul>
      </dd>
      <dt><font face="宋体" size="3">返回循环:第3次</font></dt>
      <font size="2">
      <dd><ul>
          <li><font face="宋体">loop=2 </font></li>
          <li><font face="宋体">width=2 </font></li>
          <li><font face="宋体">a_line = &quot;xx&quot; </font></li>
          <li><font face="宋体">2 is NOT less than 2 so </font></li>
          <li><font face="宋体">fall out of the loop and do what follows </font></li>
        </ul>
      </dd>
      </font>
    </dl>
    <p ALIGN="JUSTIFY"><font SIZE="3">随后是:</font></p>
    <ul>
      <pre>
      <font SIZE="3">
<font face="宋体">alert(a_line);

</font></font></pre>
      <p ALIGN="JUSTIFY"><font SIZE="3">启动一个警告对话框。</font></p>
      <p ALIGN="JUSTIFY"><font SIZE="3">这种循环运用的如此普遍以至于程序员们开发了一些简便<br>
      方式,条件循环可写成这样:</font></p>
    </ul>
    <ul>
      <pre>
      <font SIZE="3">
<font face="宋体">while (loop &lt; width)

{

	a_line += &quot;x&quot;;  //this was a_line = a_line + &quot;x&quot;;

	loop++;         //this was loop=loop+1;

}

</font></font></pre>
    </ul>
    <p><font face="宋体" size="3">首行,“x”,表示“本身加x”。若已有a_number=5,那么可<br>
    写成,a_number+=3,即是说:a_number=a_number+3。程序员<br>
    就是这么偷懒的。</font></p>
    <p ALIGN="JUSTIFY"><font face="宋体" size="2">下行,</font><font size="3"
    face="宋体">loop++,意味着“自身加1”。于是loop++即为:<br>
    loop=loop=1。它也可写成loop+=1。这样偷懒行为非常有效。</font></p>
    <p ALIGN="JUSTIFY"><font size="3" face="宋体">就象不止一种方式在一个数上加</font><font
    SIZE="3"><font face="宋体">1</font>一样,也有不止一种方法来写<br>
    一个循环。<font face="宋体">While</font>循环不是唯一的循环模式,另一流行的循环<br>
    是<font face="宋体"><a href="day4_5.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_5.html">for循环</a>。</font></font></p>
    <p align="left"><font face="宋体" size="3" color="#000000"><strong>JavaScript教程</strong></font><font
    color="#FF0000" face="宋体" size="3"><br>
    </font><font size="3" color="#FF0000">第一页</font><font size="2" face="宋体"> </font><a
    href="day4_4.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_4.html"><font SIZE="3">第四课介绍</font></a><font size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第二页</font> <a href="day4_2.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_2.html">循环介绍</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第三页</font> <a href="day4_3.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_3.html">循环的密码</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第四页</font> 再谈<font face="宋体">WHILE</font>循环</font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第五页</font> <a href="day4_5.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_5.html">For循环</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第六页</font> <a href="day4_6.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_6.html">嵌套循环</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第七页</font> <a href="day4_7.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_7.html">循环练习</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第八页</font> <a href="day4_8.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_8.html">数组</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第九页</font> <a href="day4_9.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_9.html">数组和循环</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第十页</font> <a href="day4_10.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_10.html">文件目标模块中的数组</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第十一页</font> <a href="day4_11.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_11.html">函数</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第十二页</font> <a href="day4_12.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_12.html">无参数函数</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第十三页</font> <a href="day4_13.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_13.html">参数及返回值</a></font><font
    size="2"><br>
    </font><font SIZE="3"><font color="#FF0000">第十四页</font> <a href="day4_14.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day4_14.html">多于一个参数的函数</a></font></p>
    <p align="left"><font face="宋体" size="3">[<a href="index.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/index.html">第1课</a>][<a
    href="day2_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day2_1.html">第2课</a>][<a href="day3_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day3_1.html">第3课</a>][第4课][<a
    href="day5_1.html" tppabs="http://www.pchome.net/ch/tur/pstext/teacher/javascript/day5_1.html">第5课</a>]</font></p>
    <hr align="left">
    <p><font size="2">本文由<a href="javascript:if(confirm('http://chd.126.com/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://chd.126.com/'" tppabs="http://chd.126.com/" target="_blank">《</font><font
    face="verdana, arial, geneva, sans-serif" size="2">CHD</font><font size="2">的网络教室》</a>根据<a
    href="javascript:if(confirm('http://www.webmonkey.com.cn/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.webmonkey.com.cn/'" tppabs="http://www.webmonkey.com.cn/" target="_blank">《网猴》</a>相关文章改编,版权归<a
    href="javascript:if(confirm('http://www.webmonkey.com.cn/  \n\nThis file was not retrieved by Teleport Pro, because it is addressed on a domain or path outside the boundaries set for its Starting Address.  \n\nDo you want to open it from the server?'))window.location='http://www.webmonkey.com.cn/'" tppabs="http://www.webmonkey.com.cn/" target="_blank">《网猴》</a>所有</font></td>
  </tr>
</table>
</div>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -