How do I change a global variable's value within a while statement?
TheFlooBearer (2)

In this example, I am trying to have the program change the AB variable's (Global Variable) value within a [while] statement. When I have the program print out the variable's value after the program if finished, it hasn't changed at all, no matter how many times the [while] loop is looped. Is there a way to change this?

You are viewing a single comment. View All
ArchieMaclean (613)

You've just made a very small error. It's quite easy to make. On line 9, it should be


instead of


ab+=1 is shorthand for ab=ab+1, but ab+1 just adds 1 to ab, but doesn't store the value.
Please mark this as the answer if it solved your problem :)

TheFlooBearer (2)

@ArchieMaclean Wow, thanks a lot. I make a lot of those I have noticed, But yes, that does make sense.