2012-06-06 25 views
1

我製作了一系列使用HTML5 canvas元素的圈子。我正在使用while循環來增加圓圈的大小。我試圖增加他們三個,但我不知道正確的語法。HTML5 Js增量

var cirSize = 2; 

    while (cirSize < 400) 
     { 
     ctx.beginPath(); 
     ctx.strokeStyle="#000000"; 
     ctx.arc(480,480,cirSize++,0,Math.PI*2,true); 
     ctx.stroke(); 
     alert(cirSize) 
     } 

感謝

+1

小記的價值:「增量」是指「通過增加一個」。 '增加三'是無意義的。 –

+0

@KendallFrey感謝您的意見,但廣義而言,您隨時增加金額即爲增量。 – jimbouton

回答

2

cirSize++將遞增一,因此將++cirSize。但是有一個區別。前者將返回cirSize第一個和然後增量。而後者則增量第一然後返回cirSize

var cirSize = 2; 

while (cirSize < 400) 
    { 
    ctx.beginPath(); 
    ctx.strokeStyle="#000000"; 
    ctx.arc(480,480,cirSize,0,Math.PI*2,true); 
    ctx.stroke(); 
    cirSize += 3; // here's the change. 
    alert(cirSize) 
    } 
+0

非常感謝。 – jimbouton