我有以下代码:
while(tmp->next != NULL)
{
if(tmp->code == (unsigned int)16777221)
{
CU_ASSERT_STRING_EQUAL("3GPP Zh", tmp->name);
}
if(strcmp((const char*)tmp->name, (const char*)"IUT-T Rs") == 0)
{
CU_ASSERT_EQUAL((unsigned int)16777235, tmp->code);
}
tmp = tmp->next;
}
我想做的是:一旦执行了if结构中的代码(也就是说,if条件被评估为true),我不想执行它在接下来的所有 while 循环中,我该怎么做?
最佳答案
int once = 0;
while(tmp->next != NULL)
{
if(!once && tmp->code == (unsigned int)16777221)
{
once = 1;
CU_ASSERT_STRING_EQUAL("3GPP Zh", tmp->name);
}
/* deal with subsequent if's in the same manner */
tmp = tmp->next;
}
关于c - C 中的 while 循环中的 if,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38263016/