I've been programming in Java for several years now, but I just recently returned to school to get a formal degree. I was quite surprised to learn that, on my last assignment, I lost points for using a loop like …
Why does the following work fine?
String str;
while (condition) {
str = calculateStr();
.....
}
But this one is said to be dangerous/incorrect:
while (condition) {
String str = calculateStr();
.....
}
Is it necessary to declare variables outside the loop?
I want to break a while loop of the format below which has an if statement. If that if statement is true, the while loop also must break. Any help would be appreciated.
while(something.hasnext()) {
do something...
if(contains …