Javascript 中 while 循環(huán)用法的代碼,通過本例了解一下while循環(huán)的用法,相信這對你的JavaScript編程會有所幫助。
<html>
<head>
<title>while循環(huán)</title>
</head>
<body>
<center><h2>測試while循環(huán)</h2></center>
<hr>
<script language="JavaScript">
// 變量聲明
var i = 1;
var intTotal = 0;
// 循環(huán)語句
while (i <= 5){
document.write("數(shù)字: " + i + "<br>");
intTotal += i;
i++;
}
document.write("<hr>總和: " + intTotal + "<br>");
</script>
</body>
</html