break的演示
package xingqushi;
import java.util.Scanner;
public class ComplexLoop
{
public static void main(String[] args)
{
String[] names={"a","b","cc"};
System.out.println("please inter the name:");
Scanner scan=new Scanner(System.in);
String name=scan.nextLine();
scan.close();
int i;
for(i=0;i<=names.length-1;i++)
{
if(name.equals(names[i]))
{
break;//结束循环
}
}
System.out.print(i<3?i:-1);
}
}
continue的操作
package xingqushi;
import java.util.Scanner;
public class ComplexLoop
{
public static void main(String[] args)
{
int[] numbers={78,23,19,36,42,18,9,54,31,79,47};
int sum=0;
for(int i=0;i<numbers.length;i++)
{
if(numbers[i]%2>0)
{
continue;//结束本次操作
}else
{
sum=sum+numbers[i];
}
}
System.out.println(sum);
}
}