do-while和while的区别

do-while和while的区别在于do-while最少会执行一次好吗。

先看do-while:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<script language="Javascript" type="text/javascript" >
    var i=10;
    do{
    i+=2
    }while (i<10);
    alert(i);
</script>
</head>
<body>
</body>
</html>

再看while:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<script language="Javascript" type="text/javascript" >
    var i=10;
    while (i<10){
    i+=2;
    }
    alert(i);
</script>
</head>
<body>
</body>
</html>

 

posted @ 2013-05-07 21:10  roytanlu  阅读(226)  评论(0编辑  收藏  举报