The article directories

  • Jump control statement -return

Jump control statement -return

  • Return is used in the method, indicating the method where the jump is. Note: ifreturnWritten in the bookmainMethod,Exit the program, the following code is no longer executed.

Return01.java

public class Return01 {
    public static void main(String[] args) {
        for (int i = 1; i <= 5; i++){
            if (i == 3){
                System.out.println("I look beautiful."+i);
                return;
            }
            System.out.println("Hello World!");
        }
        System.out.println("go on..."); }}Copy the code

  • Change the above return tobreak, the execution result is as follows:

  • Instead ofcontinueThe result is: