1

I am making a series of circles using the HTML5 canvas element. I am using a while loop to increment the size of the circles. I am attempting to increment them by three but I'm not sure of the correct syntax.

    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)
      }

Thanks

2
  • 1
    Minor note:'Increment' means 'increase by one'. 'Increment by three' is nonsensical. Commented Jun 6, 2012 at 14:37
  • @KendallFrey Thanks for your input but broadly speaking anytime you increase an amount it's an increment. Commented Jun 6, 2012 at 16:13

1 Answer 1

2

cirSize++ will increment by one, so will ++cirSize. But there's a difference. The former will return the value of cirSize first and then increment. While the latter will increment first and then return the value of 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)
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.