ããbreakè¯å¥é常ç¨å¨å¾ªç¯è¯å¥åå¼å
³è¯å¥ä¸ãå½breakç¨äºå¼å
³è¯å¥switchä¸æ¶ï¼å¯ä½¿ç¨åºè·³åºswitchèæ§è¡switch以åçè¯å¥ï¼å¦æ没æbreakè¯å¥ï¼åä¼ä»æ»¡è¶³æ¡ä»¶çå°æ¹ï¼å³ä¸switchï¼
表达å¼ï¼æ¬å·ä¸è¡¨è¾¾å¼å¹é
çcaseï¼å¼å§æ§è¡ï¼ç´å°switchç»æç»æã
ããå½breakè¯å¥ç¨äºdo-whileãforãwhile循ç¯è¯å¥ä¸æ¶ï¼å¯ä½¿ç¨åºç»æ¢å¾ªç¯ãèæ§è¡å¾ªç¯åé¢çè¯å¥ï¼é常breakè¯å¥æ»æ¯ä¸
ifè¯å¥èå¨ä¸èµ·ãå³æ»¡è¶³æ¡ä»¶æ¶ä¾¿
è·³åºå¾ªç¯ã
ãã示ä¾ï¼å¨vc6.0ä¸ç¼è¯éè¿
ãã#include <stdio.h>
ããint main()
ãã{
ããint num;
ããprintf("\tæ绩æ¥è¯¢\n\n");
ããprintf("请è¾å
¥èççèå·ï¼");
ããscanf("%d",&num);
ããswitch(num)
ãã{
ããcase 1001:
ããprintf("该èççæ绩æ¯95\n");
ããbreak;
ããcase 1002:
ããprintf("该èççæ绩æ¯90\n");
ããbreak;
ããcase 1003:
ããprintf("该èççæ绩æ¯60\n");
ããbreak;
ããcase 1004:
ããprintf("该èççæ绩æ¯49\n");
ããbreak;
ããcase 1005:
ããprintf("该èççæ绩æ¯85\n");
ããbreak;
ããdefault:
ããprintf("æè¾å
¥çèå·æ误ï¼\a\n");
ããbreak;
ãã}
ããreturn 0;
ãã}
ãã注æï¼
ãã1. breakè¯å¥å¯¹if-elseçæ¡ä»¶è¯å¥ä¸èµ·ä½ç¨ã
ãã2. å¨å¤å±å¾ªç¯ä¸ï¼ä¸ä¸ªbreakè¯å¥åªåå¤è·³ä¸å±ã