Below are two snippets. Please note that the difference between THEY and ONLY between programs is that one break to returnand the other at returnonce. I understand that good design practice has one exit point inside the method. But I'm not worried about the design here. If I pay extra for use break, how much extra computation / memory / clock cycle will I pay?
break to return
return
break
First program:
public boolean doThis(String[] A){ boolean indicator = false; for(int i=0; i<A.length; i++){ if(A[i].equals("Taboo")) break; for(int x=0; x<=i; x++) //some work is done here. to make indicator true or false } return indicator; }
The second program:
public boolean doThis(String[] A){ boolean indicator = false; for(int i=0; i<A.length; i++){ if(A[i].equals("Taboo")) return false; for(int x=0; x<=i; x++) //some work is done here. to make indicator true or false } return indicator; }
If your compiler is good, you pay a little less for the case of "return false".
, , "" . crummy , , . , , .
" " , , " " , , . "return false" ( , ); , , , .
. " " , "" ; , . , , , ; .
, , .