Java foundation -4.5

Loop control
in the loop defined when there are two control statements: break, continue

The main function is to break the cycle withdraw the entire structure

continue strictly speaking, only the end of the current first call (to end the current cycle)
when the execution to continue when he no longer represents the subsequent code execution in the current statement, and direct follow-up of the judging process.

Here is continue to achieve in the c goto function (know on the line and made a mess)

    public static void main(String[] args) {
        point:for(int x=0;x<3;x++) {
                for(int y=0;y<3;y++) {
                    if(x==y) {
                        continue point;
                    }
                    System.out.print(x+"、");
                }
                System.out.println();
            }
    }
>>>1、2、2、
//当x=0时与y=0相等 直接跳到for那 x变为1 x=1 y=0 输出1、 之后x=y=1 跳到for x变为2 之后...

public static void main(String[] args) {
        point:for(int x=0;x<3;x++) {
                for(int y=0;y<3;y++) {

                    System.out.print(x+"、");
                }
                System.out.println();
            }
    }
>>>0、0、0、
>>>1、1、1、
>>>2、2、2、

Guess you like

Origin www.cnblogs.com/sakura579/p/12313563.html