zoukankan      html  css  js  c++  java
  • Continue和Break

    break的用法:

    1.break用于switch语句中,终止switch语句
    2.break用于循环时,跳出循环
    3.break用于其他位置,毫无意义

    1. break用于switch语句中,终止switch语句

    public class for0915{
        public static void main(String[] args){
            int a=2;
            switch (a) {
                case 1:
                    System.out.println("天");
                case 2:
                    System.out.println("地");
                case 3:
                    System.out.println("玄");
                    break;
                case 4:
                    System.out.println("黄");
                default:
                    System.out.println("输入有误");
            }
        }
    }

    continue语句用于终止本次循环,接着开始下一次循环。

    如:public class for0915 {
        public static void main(String[] args){
            for(int i =0;i<5;i++){
                System.out.println("i的值是:"+i);
                if(i==3){
                    //跳过此次循环
                    continue;
                }
                System.out.println("continue后的输出语句:");
            }
        }
    }

  • 相关阅读:
    Leetcode Binary Tree Level Order Traversal
    Leetcode Symmetric Tree
    Leetcode Same Tree
    Leetcode Unique Paths
    Leetcode Populating Next Right Pointers in Each Node
    Leetcode Maximum Depth of Binary Tree
    Leetcode Minimum Path Sum
    Leetcode Merge Two Sorted Lists
    Leetcode Climbing Stairs
    Leetcode Triangle
  • 原文地址:https://www.cnblogs.com/yhcTACK/p/15327898.html
Copyright © 2011-2022 走看看