我在一个类似于这样的函数中有一个 do-while 循环:
do
{
// a bunch of stuff
if (something < something else)
{
return true;
}
else if (stuff > other stuff)
{
if (something != other stuff)
{
return false;
}
else
{
return true;
}
}
} while (condition);
我的问题是condition
最后。我可以跟踪这一点的唯一方法是在循环之前声明一个布尔变量,并将其值设置为与该return
值匹配并while()
在每次迭代后对其进行检查。虽然这可行,但对我来说似乎相当不雅,我想知道是否有一种方法可以让我while()
利用return
价值。