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

📄 js_loop_while.asp@output=print

📁 W3Schools tutorial..web designing
💻 ASP@OUTPUT=PRINT
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>JavaScript while Loop</title>
 
<link rel="shortcut icon" href="../favicon.ico" type="image/x-icon" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<meta name="Keywords" content="xml,tutorial,html,dhtml,css,xsl,xhtml,javascript,asp,ado,vbscript,dom,sql,colors,soap,php,authoring,programming,training,learning,beginner's guide,primer,lessons,school,howto,reference,examples,samples,source code,tags,demos,tips,links,FAQ,tag list,forms,frames,color table,w3c,cascading style sheets,active server pages,dynamic html,internet,database,development,Web building,Webmaster,html guide" />

<meta name="Description" content="Free HTML XHTML CSS JavaScript DHTML XML DOM XSL XSLT RSS AJAX ASP ADO PHP SQL tutorials, references, examples for web building." />

<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-cache" />

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "../../https@ssl./default.htm" : "../../www./default.htm");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-3855518-1");
pageTracker._initData();
pageTracker._trackPageview();
</script>

</head>

<body>

<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

<h1>JavaScript While Loop</h1>
<a href="js_loop_for.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_break.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>
<hr />
<p class="intro">Loops in JavaScript are used to execute the same block of code
a specified number of times or while a specified condition is true.</p>
<hr />

<h2>Examples</h2>
<p><a target="_blank" href="tryit.asp@filename=tryjs_while">While loop</a><br />
How to write a while loop. Use a while loop to run the
same block of code while a specified condition is true.</p>
<p><a target="_blank" href="tryit.asp@filename=tryjs_dowhile">Do while loop</a><br />
How to write a do...while loop. Use a do...while loop to run the same block of 
code while a specified condition is true. This loop will always be executed at 
least once, 
even if the condition is false, because the statements are executed before the 
condition is tested.</p>
<hr />

<h2>The while loop</h2>
<p>The while loop is used when you want the loop to execute and continue 
executing while the specified condition is true.&nbsp;</p>
<table class="ex" cellspacing="0" border="1" width="100%">
    <tr>
      <td>
        <pre>while (var&lt;=endvalue)
{
    <i>code to be executed</i>
}</pre>
      </td>
    </tr>
</table>
<p><b>Note:</b> The &lt;= 
could be any comparing statement.</p>
<p><b>Example</b></p>
<p>Explanation: The example below defines a loop that starts with i=0. The loop 
will continue to run as long as <b>i</b> is less than, or equal to 10. <b>i</b> 
will increase by 1 each time the loop runs.</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table6">
    <tr>
      <td>
        <pre>&lt;html&gt;
&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var i=0;
while (i&lt;=10)
{
document.write(&quot;The number is &quot; + i);
document.write(&quot;&lt;br /&gt;&quot;);
i=i+1;
}
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
      </td>
    </tr>
</table>
<p><b>Result</b></p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table7">
    <tr>
      <td>
        <pre>The number is 0
The number is 1
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
The number is 7
The number is 8
The number is 9
The number is 10</pre>
      </td>
    </tr>
</table>
<h2>The do...while Loop</h2>
<p>The do...while loop is a variant of the while loop. This loop will 
always execute a block of code ONCE, and then it will
repeat the loop as long as the specified condition is true. This loop will 
always be executed at least once, even if the condition is false, because the code is 
executed before the condition is tested.</p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table8">
    <tr>
      <td>
        <pre>do
{
    <i>code to be executed
</i>}
while (var&lt;=endvalue);</pre>
      </td>
    </tr>
</table>
<p><b>Example</b></p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table13">
    <tr>
      <td>
        <pre>&lt;html&gt;
&lt;body&gt;
&lt;script type=&quot;text/javascript&quot;&gt;
var i=0;
do 
{
document.write(&quot;The number is &quot; + i);
document.write(&quot;&lt;br /&gt;&quot;);
i=i+1;
}
while (i&lt;0);
&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
      </td>
    </tr>
</table>
<p><b>Result</b></p>
<table class="ex" cellspacing="0" border="1" width="100%" id="table14">
    <tr>
      <td>
        <pre>The number is 0</pre>
      </td>
    </tr>
</table>
<br />
<hr />
<a href="js_loop_for.asp"><img alt="previous" border="0" src="../images/btn_previous.gif" width="100" height="20" /></a>
<a href="js_break.asp"><img alt="next" border="0" src="../images/btn_next.gif" width="100" height="20" /></a>


<p>From <b>http://www.w3schools.com</b> (Copyright Refsnes Data)</p>

</body>
</html>

⌨️ 快捷键说明

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