break能跳出几层

今天突然想到在循环语句中用了 break 能跳出几层,顺手打了段代码测试一下

public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		while(true) {
			while(true) {
				if(true)
					break;
			}
			System.out.println("get out to the first level!");
			break;
		}
		System.out.println("get out to the second level!");
	}

}

输出结果:

结果表明,break只能跳出一层循环

猜你喜欢

转载自blog.csdn.net/godelgnis/article/details/81078310