这问题提得好好,总结了一下break,return,还有continue,例子可能不太恰当。return就是函数返回的意思。break是退出最近的循环。continue是停止当前执行的反复,开始新的反复。- package com.study.two;
- public class Test3
- {
- public static void main(String[] args) {
- for (int j = 0; j < 3; j++) {
- for (int i = 0; i < 3; i++) {
- System.out.println("i=" + i);
- continue;
- }
- System.out.println("j=.........." + j);
- }
- System.out.println("-----------------------");
- for (int j = 0; j < 3; j++) {
- for (int i = 0; i < 3; i++) {
- System.out.println("i=" + i);
- break;
- }
- System.out.println("j=.........." + j);
- }
- System.out.println("-------break与return的区别----------------");
- for (int j = 0; j < 3; j++) {
- for (int i = 0; i < 3; i++) {
- if (i == 2) {
- System.out.println("i=" + i);
- break;
- }
- }
- System.out.println("j=.........." + j);
- }
- System.out.println("-----------------------");
- for (int j = 0; j < 3; j++) {
- for (int i = 0; i < 3; i++) {
- if (i == 2) {
- System.out.println("i=" + i);
- return;
- }
- }
- System.out.println("j=.........." + j);
- }
- }
- }
复制代码 |