This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes while loop question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "while loop question" Watch "while loop question" New topic
Author

while loop question

Jesse Crockett
Ranch Hand

Joined: Feb 03, 2005
Posts: 129
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

Joined: Feb 03, 2005
Posts: 129


This works!
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14687
    
  16

String stuNameList, stuName;
while {
...
stuNameList = stuNameList + "\n" + stuName;
}

stuNameList is not initialized the first time you loop, so you can't use stuNameList + "\n"


[My Blog]
All roads lead to JavaRanch
 
wood burning stoves
 
subject: while loop question