java for 循环continue 跳转到外层

for (int i = 0; i < cardRecordsList.size(); i++) {
            BomCardRecords bomCardRecords = cardRecordsList.get(i);
            String recordsContent = bomCardRecords.getRecordsContent();
            if (i == 0){
                recordsContent += "$$$状态";
            }
            String[] contentArr = recordsContent.split("\\$\\$\\$", -1);
            List<String> needData = new ArrayList<>();
            for (int j = 0; j < contentArr.length; j++) {
                String contentColumn = contentArr[contentArr.length - 1];
                if (StringUtils.isBlank(state)) {
                    clearUpData(columns, partList, contentArr, columnArr, needData);
                    continue;
                } else {
                    String[] stateArr = state.split(" ");
                    List<String> stateList = Arrays.asList(stateArr);
                    contentColumn = contentColumn.split(",")[0];
                    if (contentColumn.equals("状态") || stateList.contains(contentColumn)) {
                        clearUpData(columns, partList, contentArr, columnArr, needData);
                        continue;
                    }
                }
            }
        }

  continue 跳出循环

如上代码我们是嵌套循环 , 当我们循环完毕时需要跳出最外层循环 , 我们只需要在跳转的的地方这么来写

        my:
        for (int i = 0; i < cardRecordsList.size(); i++) {
            BomCardRecords bomCardRecords = cardRecordsList.get(i);
            String recordsContent = bomCardRecords.getRecordsContent();
            if (i == 0){
                recordsContent += "$$$状态";
            }
            String[] contentArr = recordsContent.split("\\$\\$\\$", -1);
            List<String> needData = new ArrayList<>();
            for (int j = 0; j < contentArr.length; j++) {
                String contentColumn = contentArr[contentArr.length - 1];
                if (StringUtils.isBlank(state)) {
                    clearUpData(columns, partList, contentArr, columnArr, needData);
                    continue my;
                } else {
                    String[] stateArr = state.split(" ");
                    List<String> stateList = Arrays.asList(stateArr);
                    contentColumn = contentColumn.split(",")[0];
                    if (contentColumn.equals("状态") || stateList.contains(contentColumn)) {
                        clearUpData(columns, partList, contentArr, columnArr, needData);
                        continue my;
                    }
                }
            }
        }

这样我们就可continue到最外层循环了

posted @ 2021-05-18 09:59  JGG靖哥哥  阅读(2437)  评论(0编辑  收藏  举报