Comparison of Programming Languages (syntax) - Blocks

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 quest for certainty blocks the search for meaning. Uncertainty is the very condition to impel man to unfold his powers.
    Erich Fromm (1900–1980)

    The Bible and the Church have been the greatest stumbling blocks in the way of women’s emancipation.
    Elizabeth Cady Stanton (1815–1902)

    In any case, raw aggression is thought to be the peculiar province of men, as nurturing is the peculiar province of women.... The psychologist Erik Erikson discovered that, while little girls playing with blocks generally create pleasant interior spaces and attractive entrances, little boys are inclined to pile up the blocks as high as they can and then watch them fall down: “the contemplation of ruins,” Erikson observes, “is a masculine specialty.”
    Joyce Carol Oates (b. 1938)