Why is this an infinite loop? It should run one time


#1



https://www.codecademy.com/en/courses/javascript-beginner-en-ASGIv/2/1?curriculum_id=506324b3a7dffd00020bf661


I can't figure out why this While loop is infinitely looping. I can make this code work by changing x-100 to x--. However, I may need to use -100. I tried x - 100; (with spaces) and x-100; (with no spaces). Either way I get an infinite loop.


for (i=0; i<2; i++){
 console.log("This one counts " + i + "times!");   
}

var x = 1000;
while(x >900){
console.log("WHILE this one counts differently");
x - 100;
}


#2

x - 100 is a value, nothing more. You need an expression to change value of variable.

x = x - 100;

#3

Ok that makes sense, well kindof. I can see why x=x-100 is more clearly defined, but if we already know what x is, why is it necessary to use x= ?. Just the way it works?

Thanks!


#4

@codernatorgator,

Here a little discussion
http://stackoverflow.com/questions/16027247/value-returned-by-the-assignment