<!DOCTYPE html>
<html>
<body>
<h2>JavaScript Loops</h2>
<p id="demo"></p>
<script>
var text = "";
var i;
var n=11;
var sum=0;
for (i = 0; i < n ; i++) {
sum=sum+i;
text += "The number is " + sum + "<br>";
}
document.getElementById("demo").innerHTML = text;
</script>
</body>
</html>
輸出畫面
JavaScript Loops
The number is 0
The number is 1
The number is 3
The number is 6
The number is 10
The number is 15
The number is 21
The number is 28
The number is 36
The number is 45
The number is 55
The number is 1
The number is 3
The number is 6
The number is 10
The number is 15
The number is 21
The number is 28
The number is 36
The number is 45
The number is 55
沒有留言:
張貼留言