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: if
return
Written in the bookmain
Method,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 to
break
, the execution result is as follows:
- Instead of
continue
The result is: