I have a function defined that is designed to return either true or false value but the variable result
is not being updated by the inner if
s though they are being executed.
What concept of scoping am I unable to get here?
public boolean isEligible(String id) {
boolean result;
for(Person person : p) {
if(person.getId() == id) {
if(person.isRecovered() || person.getNumDoses() == 2) {
result = true;
}
}else {
result = false;
}
}
return result;
}
This is showing me an error: "the variable result might not have been initialized" After initializing it with false value the variable is returning me false for all iterations.
Please help me to clear the concept and provide the solution.