【发布时间】:2016-03-24 15:39:10
【问题描述】:
我的代码有问题。目标是将询问用户输入的过程嵌套在一个无限循环中,该循环仅在提供正确信息或用户单击取消时结束。以下是我的代码:
while (true) { // Loop until correct values are given or process is canceled.
// Ask for list price
#warning this area not tested (two if statements)
if (listPrice < 0) {
if (inputList.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
if (!double.TryParse(inputList.InputValue, out listPrice)) continue; // If value not correct restart loop
else break;
} else return false; // return from method, test failed (if cancel is pressed).
}
if (sewpPrice < 0) {
if (inputSEWP.ShowDialog() == System.Windows.Forms.DialogResult.OK) {
if (!double.TryParse(inputSEWP.InputValue, out sewpPrice)) continue;
else break;
} else return false; // Test automatically failed if exception was thrown trying to read pricing
}
}
但是,当调用“继续”时,整个父“if”块(“if (listPrice
此外,包含此代码的方法通过 Visual Studio 2015 中的中间窗口调用(因为此方法仍在测试中)。
我希望我尽可能清楚,非常感谢任何和所有帮助。
【问题讨论】:
标签: c# if-statement infinite-loop continue