for循环

来源:互联网 发布:手机淘宝官方下载 编辑:程序博客网 时间:2024/06/05 06:48

示例:

var str=" ";for(var i=0;i<100;i++){    str+="I will do this again";}

for循环中三部分(初始化,循环条件,自增操作)都可写成用,分割的多重表达式

上面例子可改为:

for(var i=0,str=" ";i<100;i++){    str+="I will do this again";}

也可把循环体中内容移到自增部分

for(var i=0str=" ";i<100;i++,str+="I will do this again"){    //nothing here}

也可写成这样

var i=0str=" ";for(;;;){    str+="I will do this again";    if(++i===100){        break;    }}
0 0