Java 程序测试_循环语句中的break和continue

package test;

public class Loop_Statement {
    public static  void main(String [] args)
    {
        String[] newbag = new String[] {"Bag","Key","Book"};
        
        //The usage of break
        int j = 0;
        while (j<newbag.length)
        {
            if(newbag[j] == "Key")
            {
                System.out.println("I have find the key!");
                break;
                //continue;
            }
            else
            {
                System.out.println("This is : "+newbag[j]+" , not key !");
            }
            j++;
        }
        
        //The usage of continue
        j = 0;
        while (j<newbag.length)
        {
            if (newbag[j]!="Book")
            {
                j++;
                continue;
            }
            System.out.println("I have find: "+newbag[j]);
            j++;
        }
    }
}
原文地址:https://www.cnblogs.com/ghmgm/p/4307695.html