林中誠 動態網頁設計 20121101 功課 林中誠 動態網頁設計 20121101 功課
測試do while迴圈

測試do while迴圈


<html>
 
<head>
<meta charset="big5"/>
<title>Ch6_4_4.htm</title>
</head>
<body>
<h2>測試do while迴圈</h2>
<hr/>
<script>
function showmessage()
{
var i = 1;
var intSum = 0;
var loop=0;
loop=document.myform.aaa.value;
do {
document.write("整數: " + i + "<br/>");
 intSum += i;
 i++;
} while (i <= loop);
document.write("<hr/>總和: " + intSum + "<br/>");
}
</script>
<form name="myform">
<input type="number" name="aaa" value=5>
<input type="button" value="click!!click me"onclick="showmessage()">
</form>
</body>
</html>