Blocks
A block is a notation for a group of two or more statements, expressions or other units of code that are related in such a way as to comprise a whole.
Braces (aka Curly brackets) {
... }
:
- Curly bracket programming languages: C, C++, Objective-C, Go, Java, JavaScript, ECMAScript, C#, D, Perl, PHP (
for
&loop
loops, or pass a block as argument), Scala, S-Lang, Windows PowerShell, Haskell (in do-notation)
Parentheses (
... )
- OCaml, Standard ML
Brackets
- Smalltalk (blocks are first class objects. aka closures)
begin
... end
:
- Ada, ALGOL, Pascal, Ruby (
for
,do/while
&do/until
loops), OCaml, Simula, Erlang.
do
... done
:
- Visual Basic, Fortran, TUTOR (with mandatory indenting of block body), Visual Prolog
do
... end
- Lua, Ruby (pass blocks as arguments,
for
loop)
X ... end
(e.g. if
... end
):
- Bash (
for
&while
loops), Ruby (if
,while
,until
,def
,class
,module
statements), OCaml (for
&while
loops), MATLAB (if
&switch
conditionals,for
&while
loops,try
clause,package
,classdef
,properties
,methods
,events
, &function
blocks), Lua (then
/else
&function
)
(begin
...):
- Scheme
(progn ...):
- Lisp
(do
...):
- Clojure
Indentation
- Off-side rule languages: Cobra, Haskell (in do-notation when braces are omitted), occam, Python
Others
- Bash, sh, and ksh:
if
...fi
,do
...done
,case
...esac
; - ALGOL 68:
begin
...end
,(
...)
,if
...fi
,do
...od
- Lua:
repeat
...until
- COBOL:
IF
...END-IF
,PERFORM
...END-PERFORM
Read more about this topic: Comparison Of Programming Languages (syntax)
Famous quotes containing the word blocks:
“The vast silence of Buddha overtakes
and overrules the oncoming roar
of tragic life that fills alleys and avenues;
it blocks the way of pedicabs, police, convoys.”
—Denise Levertov (b. 1923)
“The Bible and the Church have been the greatest stumbling blocks in the way of womens emancipation.”
—Elizabeth Cady Stanton (18151902)
“He has given me six hundred street signs.
The time I was dancing he built a museum.
He built ten blocks when I moved on the bed.
He constructed an overpass when I left.”
—Anne Sexton (19281974)