我有这样的代码:
main()
{
for(i=0;i<100;i++)
{
if(cond1)
func(1); //Just some logics are present here
if (cond2)
if(cond3 | cond4)
func(2);
and so on....
}
}
void func(int)
{
do somthing;
if cond5
continue;// this is for the FOR loop in main() & I know this doesnt make sense.
}
因此,根据函数'func'中的某些IF条件,我想'继续'main()中存在的FOR循环。怎么做到这一点? 提前谢谢......
答案 0 :(得分:3)
在for循环中检查func返回值。如果是试试 - 请继续。否则 - 什么都不做。
void main()
{
for(i=0;i<100;i++)
{
if(cond1)
if (func(1))
continue;//Just some logics are present here
if (cond2)
if(cond3 | cond4)
if (func(2))
continue;
and so on....
}
}
bool func(int)
{
do somthing;
bool bRes = false;
if cond5
bRes = true;// this is for the FOR loop in main() & I know this doesnt make sense.
// ....
return bRes;
}
答案 1 :(得分:1)
从你的函数返回bool并继续false。使用您的示例:
main()
{
for(i=0;i<100;i++)
{
if(cond1)
func(1); //Just some logics are present here
if (cond2)
if(cond3 | cond4)
if (!func(2))
continue;
and so on....
}
}
bool func(int)
{
do somthing;
if cond5
return false;
return true
}