• Post Reply Bookmark Topic Watch Topic
  • New Topic

Misunderstanding of variable scope?

 
F Turner
Ranch Hand
Posts: 30
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was looking at my code with the debugger in Eclipse and came across some strange behaviour, as indicated below:

Would anyone be able to tell me why I am getting the <error(s)_during_the_evaluation> message at the indicated point in the code? It is as if the value for myInteger is only 'held' within the region it is assigned to the variable, which I don't think is how Java operates. Perhaps I am just missing something obvious...

Many thanks.
 
Junilu Lacar
Sheriff
Posts: 10042
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it say what kind of errors?
 
Junilu Lacar
Sheriff
Posts: 10042
120
Android Eclipse IDE IntelliJ IDE Java Linux Mac Scala Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What do you get if you put a System.out.println(myInteger); statement at line 12?
 
Rob Spoor
Sheriff
Posts: 20820
68
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here's a hint: what is the value of myInteger if the first while loop has zero iterations (i.e. its body never gets executed)?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!