首页 > 代码库 > if语句里面continue和break的区别

if语句里面continue和break的区别

break:结束整个循环体

continue:结束本次循环

代码说明:

public static void main(String[] args) {		int x=0;		while(x++ < 10)		{		    if(x == 3)		    {		        break;		    }		    System.out.println("x="+x);		}				int y=0;				while(y++ < 10)		{		    if(y == 3)		    {		        continue;		    }		    System.out.println("y="+y);		}}

 输入:

x=1
x=2
y=1
y=2
y=4
y=5
y=6
y=7
y=8
y=9
y=10

if语句里面continue和break的区别