Content deleted Content added
ilwiki |
m Robot-assisted disambiguation (you can help!): Python programming language |
||
Line 1:
In [[computer programming]], a '''statement block''' (or '''code block''') is a section of [[computer code|code]] which is grouped together, much like a [[paragraph]]; such blocks consist of one, or more, [[statement (programming)|statements]]. Statement blocks help make code more readable by breaking up programs into logical work units.
In [[C (programming language)|C]], [[C++]], [[Java (programming language)|Java]] and some other languages, statement blocks are enclosed by [[bracket|brace]]s <tt>{}</tt>. In [[Ada programming language|Ada]], [[Pascal programming language|Pascal]], and some other languages, blocks are denoted by "<tt>begin</tt>" and "<tt>end</tt>" statements. In [[Python (programming language)|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 (programming)|scope]] of the identifiers used within.
Blocks often have subtle but important differences in semantics. In languages in the C tradition, they define identifier scope. In C++ they can be used to define object lifetime (creation and destruction). In some languages (such as [[Pico programming language|Pico]]) they are merely used for grouping expressions without notions of variable scope. In languages such as [[Smalltalk]], blocks are objects in their own right, extended with a reference to their environment of definition, i.e. [[Closure (computer science)|closures]].
|