【发布时间】:2013-09-29 09:33:40
【问题描述】:
这是我的代码:
while( Func(x) != ERR_D)
{
if(result == ERR_A)
throw...;
if(result == ERR_B)
throw...;
mydata.x = x;
}
问题是我想在 while 条件中使用result = Func(x),因为结果将在 while 循环内检查。 while 循环应该调用Func(x),直到它返回ERR_D。
我不能用
do{
result = Func(x);
if(result == ERR_A)
throw ...;
if(result == ERR_B)
throw ...;
mydata.x = x;
}while(result != ERR_D);
在我的项目中,它首先调用Func(x),这是我不想要的。
但是我试过while(result = Func(x) != ERR_D),还是不行。有什么想法可以解决这个问题吗?
【问题讨论】:
-
好吧,
x永远不会改变。也许这与它有关?很难说,因为“不起作用”可能意味着几乎任何事情,我们不知道应该发生什么。 -
var result = Func(x); while (result != ERR_D) { doStuff(); result = Func(x); }? -
在while循环中抛出异常真的有意义吗?一旦抛出一个循环,循环就会终止......
标签: c# .net while-loop conditional-statements