while循環

1.while循環

<html>
<body>

<script type="text/javascript">
i = 0
while (i <= 5)
{
document.write("數字是 " + i)
document.write("<br />")
i++
}
</script>

<h1>解釋:</h1>

<p><b>i</b> 等於 0。</p>

<p>當 <b>i</b> 小於或等於 5 時,循環將繼續運行。</p>

<p>循環每運行一次,<b>i</b> 會累加 1。</p>

</body>
</html>
 

2.do while循環

<body>

<script type="text/javascript">
i = 0
do
{
document.write("數字是 " + i)
document.write("<br />")
i++
}
while (i <= 5)
</script>

<h1>解釋:</h1>

<p><b>i</b>  等於 0。</p>

<p>循環首先會運行。</p>

<p>每循環一次,<b>i</b> 就會累加 1。</p>

<p>當 <b>i</b> 小於或等於 5 時,循環會繼續運行。</p>


</body>
</html>
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章