Information Technology Reference
In-Depth Information
What Are Statements?
The statements in C# are very similar to those of C and C++. This chapter will cover the charac-
teristics of a C# statement, as well as the flow-of-control statements provided by the language.
•A statement is a source code instruction describing a type or telling the program to per-
form an action.
￿
There are three major categories of statements, as follows:
-
Declaration statements : Statements that declare types or variables
-
Labeled statements : Statements to which control can jump
-
Embedded statements : Statements that perform actions or manage flow of control
Previous chapters have covered a number of different declaration statements, including
declarations of local variables, classes, and class members. This chapter will cover the embed-
ded statements, which do not declare types, variables, or instances. Instead, they use
expressions and flow-of-control constructs to work with the objects and variables that have
been declared by the declaration statements.
￿A simple statement consists of an expression followed by a semicolon.
￿A block is a sequence of statements enclosed by matching curly braces. The enclosed
statements can include the following:
-
Declaration statements
-
Labeled statements
-
Embedded statements
-
Nested blocks
The following code gives examples of each:
int x = 10; // Simple declaration
int z; // Simple declaration
{ // Block
int y = 20; // Simple declaration
z = x + y; // Embedded statement
top: y = 30; // Labeled statement
...
{ // Nested block
...
}
}
Search WWH ::




Custom Search