简体   繁体   English

Javascript中for循环的每个参数都有多个操作

[英]More than one operation on each parameter of the for loop in Javascript

Is there a syntax to include multiple initialization or final expression on a for loop in javascript? 是否有一种语法在javascript中的for循环中包含多个初始化或最终表达式?

For instance initialize two variables, or increment two variables. 例如,初始化两个变量,或增加两个变量。

I don't see anything about it on the MDN documentation . 我在MDN文档中没有看到任何相关内容。

I think this is what you're asking for.... 我想这就是你要求的......

for (var i = 0, a = 1; i < 10; i++, a += 2) {
    console.log(i, a);
}

output: 输出:

0 1
1 3
2 5
3 7
4 9
5 11
6 13
7 15
8 17
9 19

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM