## for loop 介紹

Loops are handy, if you want to run the same code over and over again, each time with a different value. Often this is the case when working with arrays:

• for - loops through a block of code a number of times
• for/in - loops through the properties of an object
• while - loops through a block of code while a specified condition is true
• do/while - also loops through a block of code while a specified condition is true

//變數宣告
var items=[1,2,3,4,5],
items_ch=["tse","123","abc","gg","中文"],
item={
"first":"first",
"2":"2",
"34":"34",
"1":"1",
"second":"second"
};


## 更有效的使用for loop

for(var i=0;i<items.length;i++){

}


for(var i=0;i<items.length;i++){

}


for(var i=items.length;i>0;i--){

}


var i=items.length;
while(i--){

}


## 題外話-撰寫保持ＣＰＵ使用率在50%的程式

setInterval("doLoop()",300);
function doLoop(){
console.log("do looping...");
//變數宣告與前置處理
var items=[];
for(var i=0;i<5150;i++){
items.push(i);
}
for(var i=0,itemLength=items.length;i<itemLength;i++){
console.log("");
}
}


Mac的用戶可以用iStat pro來看，結果截圖如下