c语言关于break的程序,c语言break的用法

Posted weixin_39890543

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c语言关于break的程序,c语言break的用法相关的知识,希望对你有一定的参考价值。

小编为大家整理了c语言break的用法。希望对你有帮助哦!

一、程序源代码:

#include

void main()

{

char letter;

printf("please input the first letter of someday\\n");

while ((letter=getch())!='Y')/*当所按字母为 Y 时才结束*/

{

switch (letter)

{

case'S':printf("please input second letter\\n");

if((letter=getch())=='a')

printf("saturday\\n");

else if ((letter=getch())=='u')

printf("sunday\\n");

else printf("data error\\n");

break;

case 'F':printf("friday\\n");break;

case 'M':printf("monday\\n");break;

case 'T':printf("please input second letter\\n");

if((letter=getch())=='u')

printf("tuesday\\n");

else if ((letter=getch())=='h')

printf("thursday\\n");

else printf("data error\\n");

break;

case 'W':printf("wednesday\\n");break;

default: printf("data error\\n");

}

}

}

二、break用法解析

break 语句通常用在循环语句和开关语句中。当 break 用于开关语句 switch 中时,可使

程序跳出 switch 而执行 switch 以后的语句;如果没有 break 语句,则将成为一个死循环而无法退出。当 break 语句用于do-while、 for、while循环语句中时,可使程序终止循环而执行循环后面的语句, 通常break语句总是与 if 语句联在一起。即满足条件时便跳出循环。

以上是关于c语言关于break的程序,c语言break的用法的主要内容,如果未能解决你的问题,请参考以下文章