Java关键字之---break与continue

public static void Demo_break() {
		for(int i=1; i<=10; i++){
			
			if(i == 4){
				break;    //跳出循环:当i == 4时,跳出循环,所以结果为:1 2 3
			}
			System.out.println(i);
		}
	}
public static void Demo_continue() {
		for(int i=1; i<=10; i++){
			
			if(i == 4){
				continue;    //跳出本次循环,不运行打印语句,但继续下次循环:所以结果为:1 2 3 5 6 7 8 9 10
			}
			System.out.println(i);
		}
	}

猜你喜欢

转载自blog.csdn.net/it_is_me_a/article/details/84305923