OK, that makes sense. You are incrementing a real number (one with fractional component), and the computer can't do that with total accuracy. However adding integers will be accurate. so:

I haven't included data types. "i" and "desiredLoops" should be integers, "r" a real, and you will need to be careful with "i/desiredLoops" to make sure it creates a fractional result (ie convert both to a real value before dividing).

As to the question of rising and falling values - the sin function does that anyway, so just go to higher values, something like:

r = (i/desiredLoops)*Math.PI*4; // times 4

And you can make it start at a lower value by having something like:

r = ( (i/desiredLoops) - 0.5 )*Math.PI*4;

Play with it! Use trace() a lot, and let us know what happens:)