class BreakAndContinueDemo
{
public static void main(String[] args)
{
//我写个例子,输出1-10
for(int x=1; x<=10; x++)
{
System.out.println(x);
}
System.out.println("*****");
//用break
for(int x=1; x<=10; x++)
{
//break; 错误
System.out.println(x);
break;
}
System.out.println("*****");
//用continue
for(int x=1; x<=10; x++)
{
//continue; 错误
//System.out.println(x);
//continue;
if(x%2==0)
{
//continue;
break;
}
System.out.println(x);
}
}
}
|
|