0

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

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

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.]

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.