求解释一下这个代码也能输出6个数字:
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>do...while</title>
<script type="text/javascript">
var mynum =6;//mynum初值化数值为6
do
{
document.write("数字:"+mynum+"<br/>");
mynum=mynum-1;
}
while( mynum )
</script>
</head>
<body>
</body>
</html>
输出:
数字:6
数字:5
数字:4
数字:3
数字:2
数字:1
var mynum =6;//mynum初值化数值为6
do
{debugger
document.write("数字:"+mynum+"<br/>");
mynum=mynum-1;
}
while( mynum )
这样写是先执行do循环体里面的语句在做判断
自己在循环体里打个debugger,看一看参数的变化就明白了
while(mynum) → while(mynum!=0) → while(true)