• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

can't find variable

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am having trouble with one of my variables in this code. At line 27 I declared a user input variable "yes" but in line 32 when I try to use that variable in a while loop it is claiming that the variable does not exist. I've read a little bit about nested loops which I've been told could cause these issues but I'm not entirely sure if that is what is occuring this time. Feedback would be great on what is causing this issue and how to fix.

 
Sheriff
Posts: 6029
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The variable is no longer in scope.  Good formatting will help you see this; see HowToFormatCode (that's a link).

I haven't tried it, but I believe just declaring the variable yes outside of the do/while loop will solve the problem.
 
Knute Snortum
Sheriff
Posts: 6029
157
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are other problems.  You have a brace in the wrong place.  Also, never write string1 == string2 ; you want string1.equals(string2).
 
Marshal
Posts: 64658
225
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Knute Snortum wrote:. . . You have a brace in the wrong place. . . . .

That is caused by not indenting your code correctly. After a left brace { all the code should move about 4 places to the right, and the next right brace } should be about 4 place to the left of the preceding code. If you had done that, you would have seen the incorrect } easily.
Maybe you should't use if‑else and equals() if you can use switch instead.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!