Introduction to java core technology 02

switch case

The case label can be

  • Constant expressions of type char, byte, short, int
  • Enum constant
  • Starting from java7, the case label can also be a string constant

The difference between break and continue

In the loop statement, you can use the break statement to jump out of the loop, and use the continue statement to end the loop.

1. Statement function

    1.break语句的作用
            (1)在分支结构程序设计中用break语句可以使流程跳出switch结构,继续执行switch语句下面的一个语句;
            (2)break语句可以用来从循环体内中途跳出循环体,即提前结束循环操作,接着执行循环下面的语句。
    2.continue语句的作用
            (1)continue语句是跳过循环体中剩余的语句而强制执行下一次循环操作。
            其作用为结束本次循环,即跳过循环体中下面尚未执行的语句,接着进行下一次是否执行循环的判定。

2. Matters needing attention

            (1)在循环语句中,break语句一般都是与if语句一起使用;
            (2)break语句不能用于循环语句和switch语句之外的任何其它语句中;
            (3)continue语句只能用在循环语句中。一般都是与if语句一起使用。

Three, the difference

            (1)continue语句只结束本次循环,而不是终止整个循环的执行;
            (2)break语句则是结束整个循环过程,不再判断执行循环的条件是否成立。

Guess you like

Origin blog.csdn.net/qq_36073688/article/details/111937713