Chr*_*ris 6 .net c# if-statement
我有类似的东西
bool a = true;
bool b = true;
bool plot = true;
if(plot)
{
if(a)
{
if(b)
b = false;
else
b = true;
//do some meaningful stuff here
}
//some more stuff here that needs to be executed
}
Run Code Online (Sandbox Code Playgroud)
我想打破if测试b何时变为false的语句.有点喜欢休息并继续循环.有任何想法吗?编辑:抱歉忘了包含大if语句.我想打破if(a)当b是假的但是没有突破if(plot).
Ser*_*kiy 13
您可以将逻辑提取到单独的方法中.这将允许您具有最大一级ifs:
private void Foo()
{
bool a = true;
bool b = true;
bool plot = true;
if (!plot)
return;
if (a)
{
b = !b;
//do something meaningful stuff here
}
//some more stuff here that needs to be executed
}
Run Code Online (Sandbox Code Playgroud)
if(plot)
{
if(a)
{
b= !b;
if( b )
{
//do something meaningful stuff here
}
}
//some more stuff here that needs to be executed
}
Run Code Online (Sandbox Code Playgroud)
bool a = true;
bool b = true;
bool plot = true;
if(plot && a)
{
if (b)
b = false
else
b = true;
if (b)
{
//some more stuff here that needs to be executed
}
}
Run Code Online (Sandbox Code Playgroud)
这应该做你想要的..
| 归档时间: |
|
| 查看次数: |
51859 次 |
| 最近记录: |