做{...} while(0);
do{}while(0);的用法 在我的编码中使用它是因为,我不想使用长 if else 嵌套条件语句。我最终在失败时休息并退出循环,并确保我的函数至少被遍历 1 次。
现在,问题出在代码警告工具上,我在使用do{...}while(0); 时收到警告
嵌套 if(){} else{}的用法可读性较差,复杂度较高。并让代码有死代码。
如果我排除嵌套的 if(){} else{}和do{} while(0); ,我们是否可以用其他方式让代码具有可理解的逻辑可读性?
if(status_of_funcA_ok != funcA())
{ //failure}
else if (status_of_funcB_ok != funcB())
{//failure}
else if (status_of_funcC_ok != funcC())
else
{//Great}
do{
if(status_of_funcA_ok != funcA())
break;
if (status_of_funcB_ok != funcB())
break;
if (status_of_funcC_ok != funcC())
break;
}while(0);
Run Code Online (Sandbox Code Playgroud)