- for 循环
for (初始化表达式; 条件; 递增表达式) { 语句 } var x = 3; for (var i = 0; i < x; i++) { console.log(i); } // 0 // 1 // 2
- while循环
var i = 0; while (i < 100) { console.log('i 当前为:' + i); i = i + 1; }
- do...while
do...while
循环至少运行一次,
do { 语句 } while (条件);
var x = 3; var i = 0; do { console.log(i); i++; } while(i < x);