break,continue,goto

package com.zhao.struct;

public class BreakDemo {
    public static void main(String[] args) {
        int i = 0;
        while (i<100){
            i++;
            System.out.println(i);
            if (i==30){
                break;
            }
        }
        System.out.println("123");
    }
}

============================================

package com.zhao.struct;

public class ContinueDemo {
    public static void main(String[] args) {
        int i = 0;
        while (i<100){
            i++;
            if (i%10==0){
                System.out.println();
                continue;
            }
            System.out.print(i);
        }
    }
}

======================================

package com.zhao.struct;

public class LabelDemo {
    public static void main(String[] args) {
        //Print all the prime numbers between 101-150
        //A prime number refers to a natural number that has no other factors other than 1 and itself among the natural numbers greater than 1.
        int count = 0;
        //Not recommended for use
        outer:for (int i=101;i<150;i++){
            for (int j = 2;j<i/2;j++){
                if (i % j == 0){
                    continue outer;
                }
            }
            System.out.print(i+" ");
        }
    }
}

Guess you like

Origin blog.csdn.net/m0_48114733/article/details/122589534