标号提供了一种简单的break语句所不能实现的控制循环的方法,当在循环语句中碰到break时,不管其它控制变量,都会终止。但是,当你嵌套在几层循环中想退出循环时又会怎样呢?正常的break只退出一重循环,你可以用标号标出你想退出哪一个语句。
boolean check = true; List<SysSettingModel> sysSettingModels = sysSettingDao.findAll(); if (null != sysSettingModels) { label: for (SysSettingModel ssm : sysSettingModels) { String value = ssm.getSetValue(); if (null == value || value.equals("")) { continue; } switch (ssm.getSetName()) { case "use_pull_push_schedule": if (0 == Long.parseLong(value)) { check = false; break label; } break; case "use_pull_push_rain": if (0 == Long.parseLong(value)) { check = false; break label; } break; case "use_pull_push_overload": if (0 == Long.parseLong(value)) { check = false; break label; } break; } } }