Lably
Skip to content

Block (programming)

Demarcated group of source code statements that run in sequence

  • 8 min read
  • 5 chapters
  • 6 labs on Lably

Learn it on Lably

The nature of a block varies by programming language, but there are typical features. A block usually provides for visibility scope such that an identifier defined in a block is not visible in outer, containing blocks, but is visible in inner, nested blocks unless it is masked by an identifier with the same name. A block usually provides for lifetime scope such that resources associated with an identifier are partially or fully released when control flow reaches the end of the block in which the identifier was defined.

History

The block concept was developed in the 1950s during the development of the first autocodes, and was formalized in the Algol 58 and Algol 60 reports. Algol 58 introduced the notion of the "compound statement", which was related solely to control flow. The subsequent Revised Report which described the syntax and semantics of Algol 60 introduced the notion of a block and block scope, with a block consisting of " A sequence of declarations followed by a sequence of statements and enclosed between begin and end..." in which "[e]very declaration appears in a block in this way and is valid only for that block."

Sign in to keep reading

4 more chapters are free with a Lably account.

More in Computing and communication