• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

while loop question

 
Jesse Crockett
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at this code...



Why do I get "stuNameList variable may not have been initialized"?

How come it doesn't know it's a string?
 
Jesse Crockett
Ranch Hand
Posts: 129
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


This works!
 
Christophe Verré
Sheriff
Pie
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
String stuNameList, stuName;
while {
...
stuNameList = stuNameList + "\n" + stuName;
}

stuNameList is not initialized the first time you loop, so you can't use stuNameList + "\n"
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic