-5

这是问题所在:

常量:'a'、'b'、'c'、'd';

我有很多变量,但只有这些是相互关联的:'x'、'y'、'z';

对于第一次迭代 1 有:

x1 = [value from other variables];
y1 = x1 + a;
z1 = y1 + x1 + b;
condition |c - z1| < d;

如果为真,则程序计算其他元素(从这一点我知道工作),但如果条件为假,我们有这样的事情:

x2 = x1 + e;
y2 = x2 + a;
z2 = y2 + x2 + b;
condition |c - z2| < d; 

同样,如果为假:

x3 = x2 + e;
y3 = x3 + a;
z3 = y3 + x3 + b;
condition |c - z3| < d; 

以此类推,直到满足条件。

我要解决的是从最后一次迭代中提取的循环(i)'xi'和'yi'的值以在以后的开发中使用。除非满足条件,否则我无法提取它们。

谢谢你。

4

1 回答 1

2

您可以使用while循环

var x = // value from other variables
var y = x + a;
var z = y + x + b;

while (Math.Abs(c - z) < d)
{
    x = x + e;
    y = x + a;
    z = y + x + b;
}
于 2011-12-04T00:24:03.263 回答