下面的演示代码通过while循环语句输出数字1-6
<p>75271.com,Click the button to loop through a block of as long as <em>i</em> is less than 5.</p> <button>Try it</button> <p id="demo"></p> function myFunction() { var x="",i=0; while (i<5) { x=x + "The number is " + i + "<br>"; i++; } document.getElementById("demo").innerHTML=x; }
输出结果如下:
The number is 0 The number is 1 The number is 2 The number is 3 The number is 4