首页 > 解决方案 > 检查 IF 条件然后将其绕过到 ELSE

问题描述

我有一个 IF ELSE 条件语句块。假设这是我的代码

如何在不更改A 或 B的情况下到达代码的 isTrue 的 IF ELSE?我试过return true但它不会返回,因为它在一个方法中。有什么关键字可以这样做吗?

public void test() {
 if (text1.equals("") {
   //Output error message
 } else if (text2.equals("") { 
   //Ouput error message
 .
 .
 .
 } else if (A!= null && (A > B))  {
   //GO TO ELSE condition without changing the A or B
 } else { if (isTrue){} }
}

标签: javaandroidif-statementconditional-statements

解决方案


从其他条件中取出最后一个条件:

public void test() {
   if (text1.equals("") {
      //Output error message
   } else if (text2.equals("") { 
      //Ouput error message
   } else if (A!= null && (A > B))  {
      //GO TO ELSE condition without changing the A or B
   }

   if (isTrue){ }
}

推荐阅读