I'm new to Java and working through some coursework. However, on the following piece of code I'm getting the error "Unreachable statement" when trying to compile. Any pointers as to what I'm doing wrong?
public String getDeliveredList() {
int count = 0;
while (count < deliveredList.size()){
return ("Order # " + count + deliveredList.get(count).getAsString());
count++;
}
}
Once you've returned from the function, logically it can no longer execute anything after that point -- the count++ statement will never be reached.
while (count < deliveredList.size()){
// function always ends and returns value here
return ("Order # " + count + deliveredList.get(count).getAsString());
// this will never get run
count++;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With