break語句的作用是什么呢?
雖然代碼寫對了,但是break的作用沒有弄清楚,嘗試把break語句刪除,代碼也沒有報錯。
public class HelloWorld {
??? public static void main(String[] args) {
?? ??? ?char today='日';
?? ??? ?
??????? switch(today){
??????????? case '一':
??????????? case '三':
??????????? case '五':
??????????????? System.out.println("早餐吃包子");
??????????? case '二':
??????????? case '四':
??????????? case '六':
??????????????? System.out.println("早餐吃油條");
??????????? default:
??????????????? System.out.println("吃主席套餐");
??????? }
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?????? ?
?? ?}
}
2015-04-16
break在編程語言中是終止循環(huán)體跳到循環(huán)程序最后一條語句后繼續(xù)執(zhí)行。
2015-04-16
是不會報錯,但是不加break,會把接下來的語句都輸出。
break這里的作用就是匹配caes后,跳出這個switch,不對接下來的case做判斷。