if (user_result == SUCCESS) {
if (permission_result != SUCCESS) {
reply.WriteError("error reading permissions");
relpy.Done();
return;
}
reply.WriteErrors("");
} else {
reply.WriteErrors(user_result);
}
reply.Done;
if (user_result != SUCCESS) {
reply.WriteErrors(user_result);
reply.Done;
return;
}
if (permission_result != SUCCESS) {
reply.WriteError("error reading permissions");
relpy.Done();
return;
}
reply.WriteErrors("");
reply.Done;
儘早返回這個技巧不是萬靈丹,例如:
for (int i=0; i < results.size() ; i++) {
if (result[i] != NULL) {
non_null_count++;
if (result[i] ->name !=""){
cout << "Considering candidate ..." << endl;
}
}
}
在迴圈內與儘早返回相當的技巧是continue:
for (int i=0; i < results.size() ; i++) {
if (result[i] = NULL) continue;
non_null_count++;
if (result[i] ->name == "") continue;
cout << "Considering candidate ..." << endl;
...
}