Quote:
Originally Posted by LBloom
I think I'm starting to see why the variables like num1 were treated differently by the program than the variables like positive, negative, and zero. The variables like num1 were initialized, then given a value through user input, then used for calculations / output. The variables like positive and negative were initialized, but not given a value before I wanted to manipulate them, and so that's why it didn't work.
So I had a statement like:
if num1 > 0:
pos += 1
Which didn't work because I'm trying to use the variable pos to give itself a value, basically? I know some of my phrasing might be weird, but does the above sound roughly correct?
You got parts of it right. The terminology, though, is wrong.
When you say "initialized" you mean "declared" - understanding the difference is important. So try to get your head around the terms to start using them correctly.
Declaring a normal variable does not initialise it. So the value is unknown - whatever happened to be in the given block of memory at the time will be interpreted as the type of variable.
Java will warn you when you try to
read from such a variable.
Setting the variable for the first time initialises it.
If you use a statement like
it does not "try to give itself a value" - whatever you mean by that. It simply is a short-hand version of this:
So it needs to read the value of pos, then add 1 to that, then set pos to the result of that addition.
With pos not having been set (initialised), Java will warn you.