<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Block_%28programming%29</id>
	<title>Block (programming) - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.sarg.dev/index.php?action=history&amp;feed=atom&amp;title=Block_%28programming%29"/>
	<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Block_(programming)&amp;action=history"/>
	<updated>2026-06-20T21:02:17Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.44.2</generator>
	<entry>
		<id>https://wiki.sarg.dev/index.php?title=Block_(programming)&amp;diff=240676&amp;oldid=prev</id>
		<title>imported&gt;QuantumNinus: /* See also */</title>
		<link rel="alternate" type="text/html" href="https://wiki.sarg.dev/index.php?title=Block_(programming)&amp;diff=240676&amp;oldid=prev"/>
		<updated>2025-10-29T22:14:40Z</updated>

		<summary type="html">&lt;p&gt;&lt;span class=&quot;autocomment&quot;&gt;See also&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Short description |Demarcated group of source code statements that run in sequence}}&lt;br /&gt;
{{distinguish|Block programming}}&lt;br /&gt;
{{redirect|Code block|the IDE|Code::Blocks|block-based programming|Visual programming language}}&lt;br /&gt;
{{refimprove|date=May 2010}}&lt;br /&gt;
In [[computer programming]], a &amp;#039;&amp;#039;&amp;#039;block&amp;#039;&amp;#039;&amp;#039; of [[source code]] is a grouping of [[Statement (computer science)|statements]] that [[Execution (computing)|execute]] in sequential order; top to bottom. The block structure is fundamental to [[structured programming]], where [[control structure]]s are formed with blocks. [[Syntax (programming languages)|Syntactically]], a block acts much like a single statement in that a control structure generally operates either on a single statement or a block.&lt;br /&gt;
&lt;br /&gt;
The nature of a block varies by [[programming language]], but there are typical features. A block usually provides for visibility [[scope (computer science)|scope]] such that an [[identifier]] defined in a block is not visible in outer, containing blocks, but is visible in inner, [[Nesting (computing)|nested]] blocks unless it is [[Name masking |masked]] by an identifier with the same name. A block usually provides for lifetime scope such that [[system resource |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.&lt;br /&gt;
&lt;br /&gt;
==History==&lt;br /&gt;
The block concept was developed in the 1950s during the development of the first [[autocode]]s, and was formalized in the [[Algol 58]] and [[Algol 60]] reports. Algol 58 introduced the notion of the &amp;quot;compound statement&amp;quot;, which was related solely to [[control flow]].&amp;lt;ref name=&amp;quot;algol58_report&amp;quot;&amp;gt;{{cite journal&lt;br /&gt;
|last1= Perlis |first1 = A. J. |author-link1=Alan Perlis&lt;br /&gt;
|last2= Samelson |first2= K.&lt;br /&gt;
| date = 1958&lt;br /&gt;
| title = Preliminary report: international algebraic language&lt;br /&gt;
| journal = Communications of the ACM&lt;br /&gt;
| doi = 10.1145/377924.594925&lt;br /&gt;
| publisher =ACM&lt;br /&gt;
| location = New York, NY, USA&lt;br /&gt;
| volume = 1&lt;br /&gt;
| issue = 12&lt;br /&gt;
| pages = 8–22&lt;br /&gt;
|s2cid = 28755282 | doi-access = free&lt;br /&gt;
}}&amp;lt;/ref&amp;gt; The subsequent &amp;#039;&amp;#039;Revised Report&amp;#039;&amp;#039; which described the syntax and semantics of Algol 60 introduced the notion of a block and [[block scope]], with a block consisting of &amp;quot; A sequence of declarations followed by a sequence of statements and enclosed between begin and end...&amp;quot; in which &amp;quot;[e]very declaration appears in a block in this way and is valid only for that block.&amp;quot;&amp;lt;ref name=&amp;quot;algol60_report&amp;quot;&amp;gt;{{cite journal |last1=Backus |first1=J. W. |author-link1=John Backus |last2=Bauer |first2=F. L. |author-link2=Friedrich L. Bauer |last3=Green |first3=J. |last4=Katz |first4=C. |last5=McCarthy |first5=J. |last6=Perlis |first6=A. J. |last7=Rutishauser |first7=H. |author-link7=Heinz Rutishauser |last8=Samelson |first8=K. |last9=Vauquois |first9=B. |author-link9=Bernard Vauquois |last10=Wegstein |first10=J. H. |last11=van Wijngaarden |first11=A. |last12=Woodger |first12=M. |date=May 1960 |editor1-last=Naur |editor1-first=Peter |title=Report on the Algorithmic Language ALGOL 60 |url=http://www.masswerk.at/algol60/report.htm |journal=Communications of the ACM |location=New York, NY, USA |publisher=ACM |volume=3 |issue=5 |pages=299–314 |doi=10.1145/367236.367262 |issn=0001-0782 |s2cid=278290 |access-date=2009-10-27 |doi-access=free |editor1-link=Peter Naur}}&amp;lt;/ref&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Syntax==&lt;br /&gt;
A block is demarcated in code as a separate unit, but the syntax varies by language. Notable examples include:&lt;br /&gt;
&lt;br /&gt;
; Curly braces: [[C (programming language)|C]] and many related languages delimit a block with &amp;lt;code&amp;gt;{&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;}&amp;lt;/code&amp;gt;. In fact, this is the defining quality of a [[curly brace language]].&lt;br /&gt;
&lt;br /&gt;
; Indentation: [[Python (programming language)|Python]] and [[Haskell]] use [[off-side rule |indentation]] to demarcate a block instead of delimiters as most languages do.&lt;br /&gt;
&lt;br /&gt;
; Parentheses: The [[batch file]] syntax uses &amp;lt;code&amp;gt;(&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;)&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; begin/end: The [[ALGOL]] family generally delimits a block with the keywords &amp;lt;code&amp;gt;begin&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;end&amp;lt;/code&amp;gt;; [[ALGOL 68]] uses parentheses.&lt;br /&gt;
&lt;br /&gt;
; Control verb reversed: With [[ALGOL 68]], then in [[Edsger W. Dijkstra]]&amp;#039;s 1974 [[Guarded Command Language#Selection: if|Guarded Command Language]] the conditional and iterative code block are alternatively terminated with the block reserved word &amp;#039;&amp;#039;reversed&amp;#039;&amp;#039;: e.g. &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; ~ then ~ elif ~ else ~ &amp;#039;&amp;#039;&amp;#039;fi&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;, &amp;lt;code&amp;gt;&amp;#039;&amp;#039;&amp;#039;case&amp;#039;&amp;#039;&amp;#039; ~ in ~ out ~ &amp;#039;&amp;#039;&amp;#039;esac&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt; and &amp;lt;code&amp;gt;for ~ while ~ &amp;#039;&amp;#039;&amp;#039;do&amp;#039;&amp;#039;&amp;#039; ~ &amp;#039;&amp;#039;&amp;#039;od&amp;#039;&amp;#039;&amp;#039;&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
; [[S-expression]]: With a syntactic keyword such as &amp;lt;code&amp;gt;prog&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;let&amp;lt;/code&amp;gt; as in the [[Lisp (programming language)|Lisp]] family.&lt;br /&gt;
&lt;br /&gt;
==Limitations==&lt;br /&gt;
Some languages which support declarations in a block do not support all declarations. For instance, many C-related languages do not permit a [[nested function |function definition within a block]]. And unlike its ancestor Algol, Pascal does not support the use of blocks with their own declarations inside the begin and end of an existing block; only compound statements enabling sequences of statements to be grouped together in {{code |if}}, {{code |while}}, {{code |repeat}} and other control statements.{{clarify| What does &amp;#039;existing block&amp;#039; mean? what does this mean: &amp;#039;only compound statements enabling sequences of statements to be grouped together ...&amp;#039;? |date=September 2025}}&lt;br /&gt;
&lt;br /&gt;
==Examples==&lt;br /&gt;
In the early days of computing, many languages such as [[FORTRAN IV]] and [[BASIC]] lacked block syntax except sometimes for rudimentary loop constructs. A conditional was encoded using the [[goto]] statement. In the following FORTRAN 66 code, the logical structure is less than clear due to the lack of blocks.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;fortranfixed&amp;quot;&amp;gt;&lt;br /&gt;
C     INITIALIZE VALUES TO BE CALCULATED&lt;br /&gt;
      PAYSTX = .FALSE.&lt;br /&gt;
      PAYSST = .FALSE.&lt;br /&gt;
      TAX = 0.0&lt;br /&gt;
      SUPTAX = 0.0&lt;br /&gt;
C     SKIP TAX DEDUCTION IF EMPLOYEE EARNS LESS THAN TAX THRESHOLD&lt;br /&gt;
      IF (WAGES .LE. TAXTHR) GOTO 100&lt;br /&gt;
      PAYSTX = .TRUE.&lt;br /&gt;
      TAX = (WAGES - TAXTHR) * BASCRT&lt;br /&gt;
C     SKIP SUPERTAX DEDUCTION IF EMPLOYEE EARNS LESS THAN SUPERTAX THRESHOLD&lt;br /&gt;
      IF (WAGES .LE. SUPTHR) GOTO 100&lt;br /&gt;
      PAYSST = .TRUE.&lt;br /&gt;
      SUPTAX = (WAGES - SUPTHR) * SUPRAT&lt;br /&gt;
  100 TAXED = WAGES - TAX - SUPTAX&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Blocks allow the programmer to treat a group of statements as a unit, and the default values which had to appear in initialization in this style of programming can, with a block structure, be placed closer to the decision. The following code in Jensen and Wirth Pascal shows that block structure makes it easier to see how the code could be refactored for clarity, and also makes it easier to do, because the structure of the inner conditional can easily be moved out of the outer conditional altogether and the effects of doing so are easily predicted. Use of blocks in the fragment below clarifies the programmer&amp;#039;s intent, and enables combining the resulting blocks into a nested hierarchy of [[Conditional (computer programming)|conditional]] statements. The structure of the code reflects the programmer&amp;#039;s thinking more closely, making it easier to understand and modify. The code can be made even clearer by taking the inner if statement out of the outer one altogether, placing the two blocks one after the other to be executed consecutively. Semantically, there is little difference in this case, and the use of block structure, supported by indenting for readability, makes it easy for the programmer to refactor the code.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;pascal&amp;quot;&amp;gt;&lt;br /&gt;
    if wages &amp;gt; tax_threshold then&lt;br /&gt;
        begin&lt;br /&gt;
        paystax := true;&lt;br /&gt;
        tax := (wages - tax_threshold) * tax_rate&lt;br /&gt;
        if wages &amp;gt; supertax_threshold then begin&lt;br /&gt;
            pays_supertax := true;&lt;br /&gt;
            supertax := (wages - supertax_threshold) * supertax_rate&lt;br /&gt;
        end&lt;br /&gt;
        else begin&lt;br /&gt;
            pays_supertax := false;&lt;br /&gt;
            supertax := 0&lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
    else begin&lt;br /&gt;
        paystax := false; pays_supertax := false;&lt;br /&gt;
        tax := 0; supertax := 0&lt;br /&gt;
    end;&lt;br /&gt;
    taxed := wages - tax - supertax;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In primitive languages, variables had broad scope. For instance, an integer variable called IEMPNO might be used in one part of a Fortran subroutine to denote an employee social security number (SSN), but during maintenance work on the same subroutine, a programmer might accidentally use the same variable, IEMPNO, for a different purpose, and this could result in a bug that was difficult to trace. Block structure makes it easier for programmers to control scope.&lt;br /&gt;
&lt;br /&gt;
In the following R5RS Standard [[Scheme (programming language)| Scheme]] fragment, empno is used to identify both the manager and their underlings each by their respective SSN, but because the underling SSN is declared within an inner block it does not interact with the variable of the same name that contains the manager&amp;#039;s SSN. In practice, considerations of clarity would probably lead the programmer to choose distinct variable names, but they have the choice and it is more difficult to introduce a bug inadvertently. Within the lambda expression, the variable empno refers to the SSN of an underling. The variable empno in the outer expression, referring to the manager&amp;#039;s SSN, is shadowed.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;scheme&amp;quot;&amp;gt;&lt;br /&gt;
(let ((empno (ssn-of employee-name)))&lt;br /&gt;
  (while (is-manager empno)&lt;br /&gt;
    (let ((employees (length (underlings-of empno))))&lt;br /&gt;
      (printf &amp;quot;~a has ~a employees working under him:~%&amp;quot; employee-name employees)&lt;br /&gt;
      (for-each&lt;br /&gt;
        (lambda (empno)&lt;br /&gt;
          (printf &amp;quot;Name: ~a, role: ~a~%&amp;quot;&lt;br /&gt;
                  (name-of empno)&lt;br /&gt;
                  (role-of empno)))&lt;br /&gt;
        (underlings-of empno)))))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Hoisting==&lt;br /&gt;
In some languages, a variable can be declared at function scope even within enclosed blocks. For example, in JavaScript, variables declared with &amp;lt;code&amp;gt;var&amp;lt;/code&amp;gt; have function scope.&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
{{Portal|Computer programming}}&lt;br /&gt;
* [[Basic block]]&lt;br /&gt;
* [[Block scope]]&lt;br /&gt;
* [[Closure (computer programming)]]&lt;br /&gt;
* [[Decomposition (computer science)]]&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
{{Reflist}}&lt;br /&gt;
{{Programming paradigms navbox}}&lt;br /&gt;
{{DEFAULTSORT:Statement Block}}&lt;br /&gt;
[[Category:Programming constructs]]&lt;/div&gt;</summary>
		<author><name>imported&gt;QuantumNinus</name></author>
	</entry>
</feed>