0

Is the word 'statement' in 'statement block' redundant?

In other words is a block in a program composed, by definition, of statements?

52d6c6af
  • 730

2 Answers2

4

Many languages don't have statements, only expressions. Ruby, for example, doesn't have statements, but it does have blocks:

begin
  some_expression
  some_other_expression
  a_third_expression
end

Since Ruby doesn't have statements, which means everything is an expression, which means everything has a value, obviously blocks are expressions and have values, too:

foo = begin
  some_expression
  some_other_expression
  a_third_expression
end

There are no statements in this Ruby block, since there are no statements in Ruby, period.

[Note: Ruby has a construct called block, which is not the kind of block you are asking about. It is a syntactically light-weight anonymous first-class procedure. The word "block" is also sometimes used for "documentation blocks" or "comment blocks", again, these are not the kinds of "block" you are asking about.]

Jörg W Mittag
  • 103,514
3

No. A program's text can contain "comment" or "documentation" blocks as well, and certain languages might have "data structure" blocks, like baked-in XML or JSON.

DougM
  • 6,371