Win a copy of JDBC Workbook this week in the JDBC and Relational Databases forum
or A Day in Code in the A Day in Code forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

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: 7108
184
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: 7108
184
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: 69403
276
  • 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.
 
He got surgery to replace his foot with a pig. He said it was because of this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic