Skip to Content
C语言核心技术(原书第2版)
book

C语言核心技术(原书第2版)

by Peter Prinz, Tony Crawford
August 2017
Intermediate to advanced
798 pages
17h 44m
Chinese
China Machine Press
Content preview from C语言核心技术(原书第2版)
110
|
第
6
章
6.5 无条件跳转
跳转语句(
jump statement
)可以中断当前程序的执行流程,并从另一个不同的点继续执
行程序。如果程序跳转到变量的作用域范围之外,变量会被销毁。
C
语言有四种语句会
造成无条件跳转:
break
、
continue
、
goto
和
return
。
6.5.1 break语句
break
语句只能用于循环体内或
switch
语句内,并且会使得程序流跳转到该循环或该
switch
语句后面的第一条语句。
break
语句的语法如下:
break;
因此,无论在循环体内什么位置,
break
语句都可以造成循环的结束。例如,例
6-7
的
while
循环可以依据用户的请求而结束(输入非数字的字符串),也可能因为数字超出
程序许可范围而结束。
例
6-7
:
break
语句
//
读取用户输入的分数,范围在
0
到
100
之间
//
将分数存储在数组中
//
返回值:所存储值的个数
//---------------------------------------------------------------
int getScores( short scores[ ], int len )
{
int i = 0;
puts( "Please enter scores between 0 and 100.\n"
"Press <Q> and <Return> to quit.\n" );
while ( i < len )
{
printf( "Score No. %2d: ", ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.

Read now

Unlock full access

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

算法精讲视频课程:24篇系列讲座

算法精讲视频课程:24篇系列讲座

罗伯特·塞奇威克, 凯文·韦恩(Kevin Wayne)

Publisher Resources

ISBN: 9787111562207