在switch case 语句中能否使用continue 关键字?为什么?
生活随笔
收集整理的這篇文章主要介紹了
在switch case 语句中能否使用continue 关键字?为什么?
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
在switch case 語句中能否使用continue 關(guān)鍵字?為什么?
#include <stdio.h> ?
int main() ?
{ ?
? ? int a; ?
? ? printf("input integer number: ? ? ?"); ?
? ? scanf("%d",&a); ?
? ? switch (a) ?
? ? { ?
? ? ? ? case 1:printf("Monday\n"); ?
? ? ? ? case 2:printf("Tuesday\n"); ?
? ? ? ? case 3:printf("Wednesday\n"); ?
? ? ? ? case 4:printf("Thursday\n"); ?
? ? ? ? continue; ?
? ? ? ? case 5:printf("Friday\n"); ?
? ? ? ? case 6:printf("Saturday\n"); ?
? ? ? ? case 7:printf("Sunday\n"); ?
? ? ? ? default:printf("error\n"); ?
? ? } ?
? ? return 0; ?
}?
編譯不通過!!!
答:
1)不能,除非外面有循環(huán)。
2)continue語句的作用是跳過循環(huán)本中剩余的語句,并到循環(huán)末尾。
3)continue語句只用在for、while、do-while等循環(huán)體中, 常與if條件語句一起使用, 用來加速循環(huán)。
#include <stdio.h> ?
int main() ?
{ ?
? ? int a; ?
? ? printf("input integer number: ? ? ?"); ?
? ? scanf("%d",&a); ?
? ? switch (a) ?
? ? { ?
? ? ? ? case 1:printf("Monday\n"); ?
? ? ? ? case 2:printf("Tuesday\n"); ?
? ? ? ? case 3:printf("Wednesday\n"); ?
? ? ? ? case 4:printf("Thursday\n"); ?
? ? ? ? continue; ?
? ? ? ? case 5:printf("Friday\n"); ?
? ? ? ? case 6:printf("Saturday\n"); ?
? ? ? ? case 7:printf("Sunday\n"); ?
? ? ? ? default:printf("error\n"); ?
? ? } ?
? ? return 0; ?
}?
編譯不通過!!!
答:
1)不能,除非外面有循環(huán)。
2)continue語句的作用是跳過循環(huán)本中剩余的語句,并到循環(huán)末尾。
3)continue語句只用在for、while、do-while等循環(huán)體中, 常與if條件語句一起使用, 用來加速循環(huán)。
總結(jié)
以上是生活随笔為你收集整理的在switch case 语句中能否使用continue 关键字?为什么?的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: case 关键字后面的的值有什么要求吗?
- 下一篇: return 关键字