【发布时间】:2011-02-16 08:45:27
【问题描述】:
我的 c 代码中有一个 if 条件。如果if 条件为真,我需要调用sleep(1) 系统调用并再次检查if 条件。最多必须这样做 9 次。如果在 9 次中的任何时间,if 条件失败,我应该从函数返回。如果 9 次到期,我应该调用另一个函数。为了更清楚,我将在下面编写伪代码。
function1()
{
count = 0
label : if (condition)
{
count++
sleep(1);
if(count < = 9)
goto label;
}
if(count > 9)
{
return;
}
function2(); /* if(condition) failed */
return;
} /* End of function1() */
实现上述逻辑的最佳方法是什么。我不喜欢使用goto 语句。
【问题讨论】:
标签: c logic implementation