If i have a simple chunk of code like:
public void tracePath(){
int steps = 0;
steps = bfs();
if(steps==0){
pathFound(false);
System.exit(0);
}else{
System.out.println(steps);
pathFound(true);
System.exit(0);
}
}
AFAIK this could be rewriten without the else as
public void tracePath(){
int steps = 0;
steps = bfs();
if(steps==0){
pathFound(false);
System.exit(0);
}
System.out.println(steps);
pathFound(true);
System.exit(0);
}
Is there a performance (or other logical) reason so keep (or lose) the else? or is it just (in this example) stylistic choice?
In this case it is stylistic preference because you exit at the end of the if statement. If you did not have a system.exit(0) at the end of the if, in the second example you would execute both pieces of code.