假设有一个函数,
void foo ()
{
// complex conditions
if (...) {
...
if (...) {
...
goto next;
}
if (...) {
...
goto next;
}
...
}
else if (...) {
...
if (...) {
...
goto next;
}
...
}
else {
...
}
next:
// print log, clean and return
...
}
需要判断很多复杂的情况,最后都要执行最后的 print log, clean and return 部分,请问使用以下哪种方式比较合适?
1. 继续使用 goto
2. 使用异常
3. 将 print log, clean and return 部分写成一个函数
void foo ()
{
// complex conditions
if (...) {
...
if (...) {
...
goto next;
}
if (...) {
...
goto next;
}
...
}
else if (...) {
...
if (...) {
...
goto next;
}
...
}
else {
...
}
next:
// print log, clean and return
...
}
需要判断很多复杂的情况,最后都要执行最后的 print log, clean and return 部分,请问使用以下哪种方式比较合适?
1. 继续使用 goto
2. 使用异常
3. 将 print log, clean and return 部分写成一个函数