Block structure

from Wikipedia, the free encyclopedia

The block structure (or the block for short ) is a characteristic of programming languages . A program is made up of instruction blocks. These can generally also be nested within one another; the whole program can be understood as one large, comprehensive block.

A block is a related section of instructions . Depending on the programming language, a block is enclosed by keywords such as beginand end, by curly brackets {  }or by indenting the program text together . Examples:

{ Algol 60, Pascal }
if a > 0 then
 begin
   b := b + 5;
   c := c - 2;
 end
else
   b = c - 1;
 //end if
/* C, C++, Java */
if (a > 0) {
   b += 5;
   c -= 2;
} else
   b = c - 1;
// end if

An entire block of instructions is often seen as a single instruction itself, which simplifies the description of the programming language. The if - clauses in the example having to only be described as they only sometimes (or No-) case, an include instruction - this is a statement block can stand, makes what now arbitrarily long sequences of instructions in each case.

Many programming languages, initially Algol 60 , took the principle of the block structure one step further by allowing new declarations of variables or even local procedures / subroutines at the beginning of each such block . The instruction blocks describe a scope ("lifetime") for these variables (or subroutines). These can then even cover variables with the same name "outside" .

Individual evidence

  1. HT de Beer: The History of the ALGOL Effort . (PDF; 1.2 MB) 2006, p. 40 (M.Sc. thesis, TU Eindhoven)