13.07.2015 Views

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

C# Language Specification - Willy .Net

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 15 Statements15. Statements<strong>C#</strong> provides a variety of statements. [Note: Most of these statements will be familiar to developers who haveprogrammed in C and C++. end note]statement:labeled-statementdeclaration-statementembedded-statementembedded-statement:blockempty-statementexpression-statementselection-statementiteration-statementjump-statementtry-statementchecked-statementunchecked-statementlock-statementusing-statementThe embedded-statement nonterminal is used for statements that appear within other statements. The use ofembedded-statement rather than statement excludes the use of declaration statements and labeled statementsin these contexts. [Example: The codevoid F(bool b) {if (b)int i = 44;}results in a compile-time error because an if statement requires an embedded-statement rather than astatement for its if branch. If this code were permitted, then the variable i would be declared, but it couldnever be used. (Note, however, that by placing i’s declaration in a block, the example is valid.) endexample]15.1 End points and reachabilityEvery statement has an end point. In intuitive terms, the end point of a statement is the location thatimmediately follows the statement. The execution rules for composite statements (statements that containembedded statements) specify the action that is taken when control reaches the end point of an embeddedstatement. [Example: For example, when control reaches the end point of a statement in a block, control istransferred to the next statement in the block. end example]If a statement can possibly be reached by execution, the statement is said to be reachable. Conversely, ifthere is no possibility that a statement will be executed, the statement is said to be unreachable.[Example: In the examplevoid F() {Console.WriteLine("reachable");goto Label;Console.WriteLine("unreachable");Label:Console.WriteLine("reachable");}177

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!