如何从if语句中的布尔值中断出if语句

我有类似的东西

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 } 

我想要突破if测试b何时变为false的语句。 有点喜欢rest并继续循环。 有任何想法吗? 编辑:抱歉忘了包含大if语句。 我想打破if(a)当b是假但没有突破if(plot)时。

 if(plot) { if(a) { b= !b; if( b ) { //do something meaningful stuff here } } //some more stuff here that needs to be executed } 

您可以将逻辑提取到单独的方法中。 这将允许您具有最大一级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 } 
 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 } } 

这应该做你想要的..