Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何构造一个 for 循环,以便我以 4 为增量从零迭代到 15,从零开始?换句话说,输出应该是0,3,7,11,15
除了您期望输出为 (0, 3, 7, 11, 15) 的事实,而这显然不是 4 (0 + 4 != 3) 的增量,您可以使用以下命令:
for (var i = 0; i < 16; i+=4) { alert(i); }
好吧,你可以这样做:
for( i=0; i<16; i+=i==0?3:4) { ... }