【www.gdgbn.com--php常用代码】
在JavaScript中循环使用执行相同的代码块指定的次数或在指定的条件是真实的。
范例
While
如何写while循环。使用while循环运行相同的代码块,而指定的条件是真实的。
html>
<script type="text/javascript">
i=0;
while (i<=5)
{
document.write("The number is " + i);
document.write("
");
i++;
do...while Loop语法.
do
{
code to be executed
}
while (var<=endvalue);
好下面我们来看看while的实例.
<script type="text/javascript">
var i=0;
while (i<=10)
{
document.write("The number is " + i);
document.write("
");
i=i+1;
}
</script>
结果.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再来看看do while实例.
<script type="text/javascript">
var i=0;
do
{
document.write("The number is " + i);
document.write("
");
i=i+1;
}
while (i<0);
</script>
结果为0