• 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
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it say what kind of errors?
 
Junilu Lacar
Marshal
Posts: 10409
125
Android Debian Eclipse IDE IntelliJ IDE Java Linux Mac 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: 20831
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)?
 
Gravity is a harsh mistress. But this tiny ad is pretty easy to deal with:
the new thread boost feature: great for the advertiser and smooth for the coderanch user
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!