Q
基本编程
3
A
回答
4
处理这种情况的一种常见方法是将if
语句的主体放入一个单独的函数中,然后如果由于某种原因导致函数无法完成,则从函数中间返回。函数返回后,for
循环中的其余语句将运行。
void foo(void)
{
//statements
//statements
if (something_bad_happened)
return;
//statements
//statements
if (some_other_bad_thing_happened)
return;
//statements
//statements
}
void bar(void)
{
for(..;..;..)
{
if (some_foo_is_needed)
foo();
//statements
//statements
}
}
2
你可以把你如果假人do..while
循环像这里面:
for(..;..;..)
{
do
{
if()
{
//use break somewhere here according to your logic
}
}while(false);
//statements
}
这将导致break
只跳过内部do..while
循环。
条件是false
在do..while
,因此循环只运行一次,正如预期的情况下一样。该循环仅用于允许中间的break
。
2
而不是if,使用switch语句。任何时候你都可以跳开关。这不是一个非常实用的解决方案...但它的工作原理。
for(..;..;..)
{
switch(boolean_expression) { //break just leaves this switch statement
case 0: //false is 0
break;
default: //true is not zero
//statements
if(something)
break;
//statements you want to skip
break;
}
//statements
}
1
如果我理解你的问题,你想要写一个声明中if
和转到你明显的语句只有当条件为真,那么goto
声明可能是有用的,举例来说如果//statements
只需要如果条件为真要运行:
for(..;..;..)
{
if(true)
{
goto dothis;
}
/* other statements */
return A;
dothis:;
//statements
return B;
}
的//statements
不必在for
循环与goto
,例如:
for(..;..;..)
{
if(true)
{
goto dothis;
}
/* other statements */
}
return A;
dothis:;
//statements
return B;
相关问题
- 1. 基本shell编程
- 2. C基本编程概念
- 3. 基本C编程问题
- 4. 卡西欧 - 基本编程
- 5. iPhone基本表单编程?
- 6. 基本的Ruby编程
- 7. 基本C++编程问题
- 8. codeproblem基本的android编程
- 9. 基本的R编程
- 10. C编程:基本双fscanf问题
- 11. C++ Builder - 基本的互联网编程
- 12. VS2005中的基本Windows编程问题
- 13. 期望脚本编程基础
- 14. 基于代理的编程使用本机编程语言
- 15. Python - 基本编码
- 16. 基本python编码
- 17. Python编程.....基础
- 18. 基本线程
- 19. 如何用汇编语言编写基本的SORT程序?
- 20. 记事本++基本的编程一切都很好
- 21. 编译基本的C++类
- 22. 基本汇编问题
- 23. 基本的Python编码
- 24. 对一个基本的多线程程序进行编码
- 25. 基本python程序
- 26. 基本SumNumber程序
- 27. 多线程基本教程
- 28. 移动编程基础
- 29. 基本的客户端/服务器编程
- 30. 编译基本的Hello World程序时抛出ClassNotFoundException
你必须多解释一下。你是否只需要为迭代,巢迭代或所有后续迭代? – Haris
不会破,因为在破解的情况下破解控制会完全脱离for循环 –
举一个更详细的例子.. – Haris