js循环
原创
©著作权归作者所有:来自51CTO博客作者hoho_12的原创作品,请联系作者获取转载授权,否则将追究法律责任
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
</head>
<body>
<script type="text/javascript">
for(var i = 0; i < 10; i++) {
for(var j = 0; j < i; j++) {
document.write("*");
}
document.write("<br/>");
}
var m = 0;
var result = 0;
while(m <= 100) {
result += m;
m++;
}
document.write("0+1+2...+100 = " + result);
document.write("<hr>");
//for in
//定义数组
var arr = new Array();
//赋值
arr[0] = 10;
arr[1] = 100;
arr[2] = 1000;
arr[3] = 10000;
//使用for ... in 遍历
//for(变量 in 数组)
//每次循环,都取出数组的下标
for(var num in arr) {
document.write(arr[num]);
document.write("<br/>");
}
</script>
</body>
</html>