`
talin2010
  • 浏览: 520725 次
  • 性别: Icon_minigender_1
  • 来自: 河北
社区版块
存档分类
最新评论

15.9 Jump statements

阅读更多
Jump statements unconditionally transfer control.
jump-statement:
break-statement
continue-statement
goto-statement
return-statement
throw-statement
The location to which a jump statement transfers control is called the
target of the jump statement.
When a jump statement occurs within a block, and the target of that jump
statement is outside that block, the
jump statement is said to exit the block. While a jump statement may
transfer control out of a block, it can
never transfer control into a block.
Execution of jump statements is complicated by the presence of intervening
try statements. In the absence
of such try statements, a jump statement unconditionally transfers control
from the jump statement to its
target. In the presence of such intervening try statements, execution is
more complex. If the jump statement
exits one or more try blocks with associated finally blocks, control is
initially transferred to the
finally block of the innermost try statement. When and if control reaches
the end point of a finally
block, control is transferred to the finally block of the next enclosing
try statement. This process is
repeated until the finally blocks of all intervening try statements have
been executed.
[Example: In the example
Chapter 15 Statements
191
using System;
class Test
{
static void Main() {
while (true) {
try {
try {
Console.WriteLine("Before break");
break;
}
finally {
Console.WriteLine("Innermost finally block");
}
}
finally {
Console.WriteLine("Outermost finally block");
}
}
Console.WriteLine("After break");
}
}
the finally blocks associated with two try statements are executed before
control is transferred to the target
of the jump statement.
The output produced is as follows:
Before break
Innermost finally block
Outermost finally block
After break
end example]
15.9.1 The break statement
The break statement exits the nearest enclosing switch, while, do, for, or
foreach statement.
break-statement:
break ;
The target of a break statement is the end point of the nearest enclosing
switch, while, do, for, or
foreach statement. If a break statement is not enclosed by a switch, while,
do, for, or foreach
statement, a compile-time error occurs.
When multiple switch, while, do, for, or foreach statements are nested
within each other, a break
statement applies only to the innermost statement. To transfer control
across multiple nesting levels, a goto
statement (§15.9.3) must be used.
A break statement cannot exit a finally block (§15.10). When a break
statement occurs within a
finally block, the target of the break statement must be within the same
finally block; otherwise a
compile-time error occurs.


A break statement is executed as follows:
? If the break statement exits one or more try blocks with associated
finally blocks, control is
initially transferred to the finally block of the innermost try statement.
When and if control reaches
the end point of a finally block, control is transferred to the finally
block of the next enclosing try
statement. This process is repeated until the finally blocks of all
intervening try statements have
been executed.
? Control is transferred to the target of the break statement.
Because a break statement unconditionally transfers control elsewhere, the
end point of a break statement
is never reachable.
C# LANGUAGE SPECIFICATION
192
15.9.2 The continue statement
The continue statement starts a new iteration of the nearest enclosing
while, do, for, or foreach
statement.
continue-statement:
continue ;
The target of a continue statement is the end point of the embedded
statement of the nearest enclosing
while, do, for, or foreach statement. If a continue statement is not
enclosed by a while, do, for, or
foreach statement, a compile-time error occurs.
When multiple while, do, for, or foreach statements are nested within each
other, a continue
statement applies only to the innermost statement. To transfer control
across multiple nesting levels, a goto
statement (§15.9.3) must be used.
A continue statement cannot exit a finally block (§15.10). When a continue
statement occurs within
a finally block, the target of the continue statement must be within the
same finally block;
otherwise a compile-time error occurs.
A continue statement is executed as follows:
? If the continue statement exits one or more try blocks with associated
finally blocks, control is
initially transferred to the finally block of the innermost try statement.
When and if control reaches
the end point of a finally block, control is transferred to the finally
block of the next enclosing try
statement. This process is repeated until the finally blocks of all
intervening try statements have
been executed.
? Control is transferred to the target of the continue statement.
Because a continue statement unconditionally transfers control elsewhere,
the end point of a continue
statement is never reachable.
15.9.3 The goto statement
The goto statement transfers control to a statement that is marked by a
label.
goto-statement:
goto identifier ;
goto case constant-expression ;
goto default ;
The target of a goto identifier statement is the labeled statement with the
given label. If a label with the
given name does not exist in the current function member, or if the goto
statement is not within the scope of
the label, a compile-time error occurs. [Note: This rule permits the use of
a goto statement to transfer
control out of a nested scope, but not into a nested scope. In the example
using System;
class Test
{
static void Main(string[] args) {
string[,] table = {
{"red", "blue", "green"},
{"Monday", "Wednesday", "Friday"}
};
foreach (string str in args) {
int row, colm;
for (row = 0; row <= 1; ++row)
for (colm = 0; colm <= 2; ++colm)
if (str == table[row,colm])
goto done;
Chapter 15 Statements
193
Console.WriteLine("{0} not found", str);
continue;
done:
Console.WriteLine("Found {0} at [{1}][{2}]", str, row, colm);
}
}
}
a goto statement is used to transfer control out of a nested scope. end
note]
The target of a goto case statement is the statement list in the
immediately enclosing switch statement
(§15.7.2) which contains a case label with the given constant value. If
the goto case statement is not
enclosed by a switch statement, if the constant-expression is not
implicitly convertible (§13.1) to the
governing type of the nearest enclosing switch statement, or if the nearest
enclosing switch statement
does not contain a case label with the given constant value, a compile-time
error occurs.


The target of a goto default statement is the statement list in the
immediately enclosing switch statement
(§15.7.2), which contains a default label. If the goto default statement
is not enclosed by a switch
statement, or if the nearest enclosing switch statement does not contain a
default label, a compile-time
error occurs.
A goto statement cannot exit a finally block (§15.10). When a goto
statement occurs within a
finally block, the target of the goto statement must be within the same
finally block, or otherwise a
compile-time error occurs.
A goto statement is executed as follows:
? If the goto statement exits one or more try blocks with associated
finally blocks, control is initially
transferred to the finally block of the innermost try statement. When and
if control reaches the end
point of a finally block, control is transferred to the finally block of
the next enclosing try
statement. This process is repeated until the finally blocks of all
intervening try statements have
been executed.
? Control is transferred to the target of the goto statement.
Because a goto statement unconditionally transfers control elsewhere, the
end point of a goto statement is
never reachable.
15.9.4 The return statement
The return statement returns control to the caller of the function member
in which the return statement
appears.
return-statement:
return expressionopt ;
A return statement with no expression can be used only in a function member
that does not compute a
value; that is, a method with the return type void, the set accessor of a
property or indexer, the add and
remove accessors of an event, an instance constructor, static constructor,
or a destructor.
A return statement with an expression can only be used in a function member
that computes a value, that
is, a method with a non-void return type, the get accessor of a property or
indexer, or a user-defined
operator. An implicit conversion (§13.1) must exist from the type of the
expression to the return type of the
containing function member.
It is a compile-time error for a return statement to appear in a finally
block (§15.10).
A return statement is executed as follows:
? If the return statement specifies an expression, the expression is
evaluated and the resulting value is
converted to the return type of the containing function member by an
implicit conversion. The result of
the conversion becomes the value returned to the caller.
C# LANGUAGE SPECIFICATION
194
? If the return statement is enclosed by one or more try blocks with
associated finally blocks,
control is initially transferred to the finally block of the innermost try
statement. When and if
control reaches the end point of a finally block, control is transferred to
the finally block of the
next enclosing try statement. This process is repeated until the finally
blocks of all enclosing try
statements have been executed.
? Control is returned to the caller of the containing function member.
Because a return statement unconditionally transfers control elsewhere, the
end point of a return
statement is never reachable.
15.9.5 The throw statement
The throw statement throws an exception.
throw-statement:
throw expressionopt ;
A throw statement with an expression throws the value produced by
evaluating the expression. The
expression must denote a value of the class type System.Exception or of a
class type that derives from
System.Exception. If evaluation of the expression produces null, a
System.NullReferenceException is thrown instead.
A throw statement with no expression can be used only in a catch block, in
which case, that statement rethrows
the exception that is currently being handled by that catch block.
Because a throw statement unconditionally transfers control elsewhere, the
end point of a throw statement
is never reachable.
When an exception is thrown, control is transferred to the first catch
clause in an enclosing try statement
that can handle the exception. The process that takes place from the point
of the exception being thrown to
the point of transferring control to a suitable exception handler is known
as exception propagation.
Propagation of an exception consists of repeatedly evaluating the following
steps until a catch clause that
matches the exception is found. In this description, the throw point is
initially the location at which the
exception is thrown.
? In the current function member, each try statement that encloses the
throw point is examined. For each
statement S, starting with the innermost try statement and ending with the
outermost try statement, the
following steps are evaluated:


If the try block of S encloses the throw point and if S has one or more
catch clauses, the catch clauses
are examined in order of appearance to locate a suitable handler for the
exception. The first catch clause
that specifies the exception type or a base type of the exception type is
considered a match. A general catch
(§15.10) clause is considered a match for any exception type. If a
matching catch clause is located, the
exception propagation is completed by transferring control to the block of
that catch clause.
Otherwise, if the try block or a catch block of S encloses the throw point
and if S has a finally block,
control is transferred to the finally block. If the finally block throws
another exception, processing of
the current exception is terminated. Otherwise, when control reaches the
end point of the finally block,
processing of the current exception is continued.
? If an exception handler was not located in the current function member
invocation, the function member
invocation is terminated. The steps above are then repeated for the caller
of the function member with a
throw point corresponding to the statement from which the function member
was invoked.
? If the exception processing terminates all function member invocations in
the current thread, indicating
that the thread has no handler for the exception, then the thread is itself
terminated. The impact of such
termination is implementation-defined.
分享到:
评论

相关推荐

    mybatisMapped报错 Statements collection does not contain value for

    ### mybatisMapped报错 Statements collection does not contain value for 在使用MyBatis框架进行数据库操作时,可能会遇到“Mapped Statements collection does not contain value for”这样的错误提示。这通常...

    pg_stat_statements.so(centos 7.3 x64)

    复制到 pgsql-12/lib 目录下就...shared_preload_libraries = 'timescaledb, pg_stat_statements' # (change requires restart) pg_stat_statements.max = 10000 pg_stat_statements.track = all 最后重启postgrelSQL

    HANA SQLStatements ALL

    标题 "HANA SQLStatements ALL" 指的是 SAP HANA 数据库系统中的 SQL 语句大全,这通常涵盖了用于各种报告的 SQL 查询和操作。在 SAP HANA 中,SQL(结构化查询语言)是用于管理和处理数据库的标准语言,它允许用户...

    SQLStatements.zip

    标题“SQLStatements.zip”暗示了这个压缩包包含与SQL语句相关的资料,特别是针对SAP HANA数据库管理系统。描述提到“HANA script for Admin”,这表明这些内容是为HANA数据库管理员准备的,可能涉及管理和优化...

    5_thethreefinancial_statements_

    标题 "5_thethreefinancial_statements_" 暗示了我们关注的核心是财务报表的三大主要组成部分:资产负债表(Balance Sheet)、利润表(Income Statement)和现金流量表(Cash Flow Statement)。这三份报表共同提供...

    IntroSQL_V4_All_SQL_Statements

    从给定的文件信息中,我们可以提取到一系列与MySQL数据库管理相关的知识点,这些知识点主要集中在数据库的创建、用户管理、权限授予以及数据表的构建上。以下是对这些知识点的详细阐述: ### 数据库用户管理 ...

    2017 Statutory Annual Report including IFRS Financial Statements

    根据提供的文件信息,我们可以从这份2017年度法定报告中提炼出以下几个关键知识点: ### 一、公司概况 #### 1.1 公司历史与发展 - **STMicroelectronics N.V.** 是一家全球领先的半导体公司。...

    Structured Programming with go to Statements

    ### 结构化编程与goto语句:一场历史的辩论 #### 概述 在计算机科学领域,关于结构化编程(Structured Programming)与goto语句的争议堪称经典,它不仅是编程语言设计史上的一个重要篇章,也深刻影响了软件工程的...

    C++语句和程序结构(英文)

    * 跳转语句(Jump statements):用于控制程序的执行流程,例如break、continue、return等。 * 表达式语句(Expression statements):用于计算表达式的值,例如数学运算、比较运算等。 * 复合语句(Compound ...

    02 - Financial Statements, Cash Flow, and Taxes

    ### 金融报表、现金流与税收 #### 一、引言 在投资领域,尤其是在寻找具有增长潜力的投资标的时,理解并分析企业的财务状况至关重要。彼得·林奇(Peter Lynch),这位曾管理过价值100亿美元的富达麦哲伦基金...

    SQL-statements-Collection.rar_Grant_sql statements

    下列语句部分是MsSql语句,不可以在access中使用。 SQL分类: DDL—数据定义语言(CREATE,ALTER,DROP,DECLARE) DML—数据操纵语言(SELECT,DELETE,UPDATE,INSERT) DCL—数据控制语言(GRANT,REVOKE,COMMIT...

    inconsistent return statements(解决方案).md

    inconsistent return statements(解决方案).md

    Textual Analysis of Customer Statements for Quality Control

    Textual Analysis of Customer Statements for Quality Control and Help Desk Support

    .predicates-quantified-statements-1.np

    .predicates-quantified-statements-1.np

    论文研究-增量式隐私保护数据挖掘研究.pdf

    描述了隐私保护数据挖掘技术研究进展。针对隐私保护关联规则挖掘算法EMASK计算效率较低,同时不适用于动态变化数据库等的问题,提出基于粒度计算的增量式隐私保护数据挖掘算法BIEMASK。该算法用粒度计算的思想对...

    pg_log_statements:PostgreSQL扩展,用于记录特定数据库会话SQL语句

    pg_log_statements pg_log_statements是一个PostgreSQL扩展,它允许记录特定数据库会话SQL语句:可以为特定服务器进程设置log_statement ,而不是在实例级别或数据库级别设置log_statement参数。安装编译中可以使用...

    Laravel开发-bank-statements-wrapper

    【Laravel开发-bank-statements-wrapper】是一个专为在 Laravel 框架中处理银行交易数据的API包装器。这个项目旨在简化与银行服务API的交互,帮助开发者更高效地集成银行对账单数据到自己的应用程序中。通过使用此...

    财务会计 第一章the financial statements.pptx

    财务会计 第一章the financial statements.pptx

    8.2 Optimizing SQL Statements

    在数据库应用开发中,SQL语句是核心执行逻辑的实现方式,无论是通过解释器直接执行还是通过API在后台提交。为了提高应用性能,尤其是MySQL数据库应用,优化SQL语句显得至关重要。本部分将深入探讨如何优化各种SQL...

    MATLAB课件:ch6_loop_statements.pdf

    MATLAB课件:ch6_loop_statements.pdf

Global site tag (gtag.js) - Google Analytics