Statement block

Statement block

In computer programming, a statement block (or code block) is a section of code which is grouped together, much like a paragraph; such blocks consist of one, or more, statements. Statement blocks help make code more readable by breaking up programs into logical work units.

In C, C++, Java and some other languages, statement blocks are enclosed by curly braces {}. In Algol, Pascal, Ada, and some other languages, they are denoted by "begin" and "end" statements. In Python they are indicated by indentation (the "Off-side rule"). Unlike paragraphs, statement blocks can be nested; that is, with one block inside another. Blocks often define the scope of the identifiers used within.

Blocks become more independent when they can have their own variables, i.e. if identifiers defined inside a block cannot be referred to from outside that block. Languages without lexical scoping such as Javascript and Pico cannot support this in principle, but many languages with lexical scoping still don't support it for nested blocks (e.g., some dialects of C, C#), while others do (e.g. Algol 68, other dialects of C, VB.NET).

In C++, blocks can be used to define object lifetime (creation and destruction). In languages such as Smalltalk, blocks are objects in their own right, extended with a reference to their environment of definition, i.e. closures.

A typical statement block

int main(){ return 0;}

A nested statement block

int main(){ int x = 1;

if (x = 1) { x++; } return 0;}

Other formats

Java programmers typically use a slightly different convention for placing the braces. The opening brace is on the same line as the method declaration:

int main() { return 0;}

int main() {

int x=1;

if (x = 1) { x++; }

return 0;}

Visual Basic requires an explicit End statement, as follows:

If x > 0 Then

y = y + x

End If

For i = 1 To 10

DoSomething(i)

Next ' or Next i

SQL Server and some other languages (e.g. Pascal) use Begin ... End blocks

IF y IS NOT NULLBEGIN SELECT * FROM employee WHERE name = yEND

ee also

* Structured programming
* Lexical scope
* Closure (computer science)


Wikimedia Foundation. 2010.

Игры ⚽ Поможем решить контрольную работу

Look at other dictionaries:

  • Block — may refer to: * A way of controlling train movement in railway signalling * Postage stamp block, an attached group of postage stampsObjects* A large concrete or stone brick * Block (sailing), a single or multiple pulley used on sailboats *… …   Wikipedia

  • Statement (programming) — In computer programming a statement can be thought of as the smallest standalone element of an imperative programming language. A program is formed by a sequence of one or more statements. A statement will have internal components (eg,… …   Wikipedia

  • Block structure — * In mathematics, block structure is a possible property of matrices see block matrix. * in computer science, a programming language has block structure if it features statement blocks, which assists structured programming …   Wikipedia

  • Block (programming) — In computer programming, a block is a section of code which is grouped together. Blocks consist of one or more declarations and statements. A programming language that permits the creation of blocks, including blocks nested within other blocks,… …   Wikipedia

  • Block book — Apocalypse page Biblia Pauperum or Bible of the Poor , woodcut illustrations w …   Wikipedia

  • block — [[t]blɒ̱k[/t]] ♦♦ blocks, blocking, blocked 1) N COUNT: usu with supp, oft N of n A block of flats or offices is a large building containing them. ...blocks of council flats. ...a white painted apartment block. 2) N COUNT A block in a town is an… …   English dictionary

  • Block statue (Egyptian) — The block statue is a type of memorial statue created because of the easy functions of it that follow. It is a memorializing statue, and ranges from ornate and detailed, to more course, and simpler, for the least famous individuals, or… …   Wikipedia

  • Block & Bridle — The National Block Bridle Club (B B) is a college club founded on December 2, 1919, in Chicago by Iowa State University, Kansas State University, University of Missouri, and University of Nebraska. Today, Block Bridle has 92 college chapters in… …   Wikipedia

  • Switch statement — In computer programming, a switch statement is a type of control statement that exists in most modern imperative programming languages (e.g., Pascal, C, C++, C#, and Java). Its purpose is to allow the value of a variable or expression to control… …   Wikipedia

  • H&R Block — H R Block, Inc. Type Public (NYSE: HRB) S P 500 Component Founded …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”