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:

    Good blocks of oak it was I split,
    As large around as the chopping block;
    And every piece I squarely hit
    Fell splinterless as a cloven rock.
    Robert Frost (1874–1963)

    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 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)