- Statement block
In
computer programming , a statement block (or code block) is a section of code which is grouped together, much like aparagraph ; 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 asJavascript 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 asSmalltalk , blocks are objects in their own right, extended with a reference to their environment of definition, i.e. closures.A typical statement block
A nested statement block
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:
Visual Basic requires an explicit End statement, as follows:
SQL Server and some other languages (e.g. Pascal) use Begin ... End blocks
ee also
*
Structured programming
*Lexical scope
*Closure (computer science)
Wikimedia Foundation. 2010.