I'm studing a code wich has this code:
public void add(StockUpdate newStockUpdate) {
for (StockUpdate stockUpdate : data) {
if (stockUpdate.getStockSymbol().equals(newStockUpdate.getStockSymbol())) {
if (stockUpdate.getPrice().equals(newStockUpdate.getPrice())) {
return;
}
break;
}
}
/* data.add mathod checks the new data against the existing data. If no change is found, the update is discarded. */
this.data.add(0, newStockUpdate);
notifyItemInserted(0);
}
I just want to know if the return
and the break
statements in this code are, in any way, different from each other. Because I tested a similar example outside this code and both return
and break
stopped the loop and terminates the function.