Programming Languages – Difference Between a Statement and a Keyword

keywordprogramming-languagesterminology

After calling return a statement, it was brought out to me in the comments:

return isn't a statement, it's the keyword that starts the return statement.

What is the difference between a statement and a keyword that starts a statement?

Best Answer

What's the difference between a sentence and a noun that starts a sentence? ;-)

return is a keyword, which means it's one of a few basic terms (tokens) of the language. They are privileged, each reserved for a special purpose and having special meaning (compare this with run of the mill identifiers/names).

A statement is (in broad terms - specific differ between languages) a higher-level unit of the language, akin to (a particular kind of) sentence in natural language. Statements include return 1+1; and foo(bar);, but generally not expressions like 1+1 or foo(bar).

Keywords often form part of statements (e.g. return introduces a return statement), but they never make a full statement on their own - even return; still needs a statement terminator.