返回顶部

收藏

JavaScript中do while循环语句的使用代码演示

更多
<!DOCTYPE html>
<html>
<body>

<p>Click the button to loop through a block of as long as <em>i</em> is less than 5.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>

<script>
function myFunction()
{
var x="",i=0;
do
  {
  x=x + "The number is " + i + "<br>";
  i++;
  }
while (i<5)  
document.getElementById("demo").innerHTML=x;
}
</script>

</body>
</html>

                                输出结果如下
The number is 0
The number is 1
The number is 2
The number is 3
The number is 4

标签:do,while,循环,JavaScript

收藏

0人收藏

支持

0

反对

0

发表评论