The for loop does not run like I would expect it to. I would expect the for loop to run only once, but when I run it, it shows an animation.
The programming environment I am using: https://www.khanacademy.org/computing/computer-programming/programming/arrays/pp/project-make-it-rain
var xPositions = [200];
var yPositions = [0];
draw = function() {
background(204, 247, 255);
for (var i = 0; i < xPositions.length; i++) {
noStroke();
fill(0, 200, 255);
ellipse(xPositions[i], yPositions[i], 10, 10);
yPositions[i] += 5;
}
};
When we say i++
then the condition i < xPositions.length
is no longer true.
So why does the the loop run more than once?
I was told that because the draw function is called forever, the loop will also get called forever.
But, the second time the loop tries to run, the condition of the for loop is not met and therefore should not run.
Thanks.
Blockquote
.
Blockquote