Will Dev wrote:Thank you for your response Liutauras.
So the y value maintains it's value from the previous loop each time. is that a mathematical thing or a java while loop thing.
I'd say it's a scope of the variable thing.
When a variable is declared, it has a scope - a section of the code it is valid within. When you have a for loop:
i is only valid for the scope of the for loop - the section between the two curly braces. It's called a block variable.
In this code, x and y are local variables - they are only valid within the main() method. If you called another method, x and y would not be valid in that method because they only exist in main() (although, a method you call could have its *own* variables called x and y, they'd just be different ones from *these* x and y.)
What do you think would happen if you moved y so it was declared within the while loop?