Content deleted Content added
m →References: wikilink |
JavaSucksMan (talk | contribs) →Syntax: added Haskell to offside rule |
||
(10 intermediate revisions by 10 users not shown) | |||
Line 3:
{{redirect|Code block|the IDE|Code::Blocks|block-based programming|Visual programming language}}
{{refimprove|date=May 2010}}
{{Programming paradigms}}▼
In [[computer programming]], a '''block''' or '''code block''' or '''block of code''' is a lexical structure of [[source code]] which is grouped together. Blocks consist of one or more [[Declaration (computer programming)|declarations]] and [[Statement (computer science)|statements]]. A [[programming language]] that permits the creation of blocks, including blocks [[Nesting (computing)|nested]] within other blocks, is called a '''block-structured programming language'''. Blocks are fundamental to [[structured programming]], where [[control structure]]s are formed from blocks.
Line 22 ⟶ 21:
| issue = 12
| pages = 8–22
|s2cid = 28755282 | doi-access = free
==Syntax==
Blocks use different syntax in different languages.
* the [[ALGOL]] family in which blocks are delimited by the keywords "<code>begin</code>" and "<code>end</code>" or equivalent. In [[C (programming language)|C]], blocks are delimited by curly braces - "<code>{</code>" and "<code>}</code>". [[ALGOL 68]] uses parentheses.
* Parentheses - "<code>(</code>" and "<code>)</code>", are used in the MS-DOS [[batch language]]
* [[off-side rule|indentation]], as in [[Python (programming language)|Python]] and [[Haskell]]
* [[s-expression]]s with a syntactic keyword such as <code>prog</code> or <code>let</code> (as in the [[Lisp (programming language)|Lisp]] family)
* In 1968 (with [[ALGOL 68]]), then in [[Edsger W. Dijkstra]]'s 1974 [[Guarded Command Language#Selection: if|Guarded Command Language]] the conditional and iterative code block are alternatively terminated with the block reserved word ''reversed'': e.g. <code><u>'''if'''</u> ~ <u>then</u> ~ <u>elif</u> ~ <u>else</u> ~ <u>'''fi'''</u></code>, <code><u>'''case'''</u> ~ <u>in</u> ~ <u>out</u> ~ <u>'''esac'''</u></code> and <code><u>for</u> ~ <u>while</u> ~ <u>'''do'''</u> ~ <u>'''od'''</u></code>
Line 39:
The semantic meaning of a block is twofold. Firstly, it provides the programmer with a way for creating arbitrarily large and complex structures that can be treated as units. Secondly, it enables the programmer to limit the scope of variables and sometimes other objects that have been declared.
In early languages such as [[Fortran IV]] and [[BASIC]], there were no statement blocks or control structures other than simple forms of loops. Conditionals were implemented using conditional [[goto]] statements:
<syntaxhighlight lang="fortranfixed">
Line 127:
==References==
{{Reflist}}
▲{{Programming paradigms navbox}}
{{DEFAULTSORT:Statement Block}}
[[Category:Programming constructs]]
|