<p>I'm asking with regards to c#, but I assume its the same in most other languages.</p>

<p>Does anyone have a good definition of <em>expressions</em> and <em>statements</em> and what the differences are?</p>

[{'answer_id': 19138, 'author': 'Mark Cidade', 'author_id': 1659, 'author_profile': 'https://Stackoverflow.com/users/1659', 'pm_score': 3, 'selected': False, 'text': "<p>Expressions can be evaluated to get a value, whereas statements don't return a value (they're of type <em>void</em>).</p>\n\n<p>Function call expressions can also be considered statements of course, but unless the execution environment has a special built-in variable to hold the returned value, there is no way to retrieve it.</p>\n\n<p>Statement-oriented languages require all procedures to be a list of statements. Expression-oriented languages, which is probably all functional languages, are lists of expressions, or in tha case of LISP, one long S-expression that represents a list of expressions.</p>\n\n<p>Although both types can be composed, most expressions can be composed arbitrarily as long as the types match up. Each type of statement has its own way of composing other statements, if they can do that all. Foreach and if statements require either a single statment or that all subordinate statements go in a statement block, one after another, unless the substatements allow for thier own substatements. </p>\n\n<p>Statements can also include expressions, where an expression doesn't really include any statements. One exception, though, would be a lambda expression, which represents a function, and so can include anything a function can iclude unless the language only allows for limited lambdas, like Python's single-expression lambdas. </p>\n\n<p>In an expression-based language, all you need is a single expression for a function since all control structures return a value (a lot of them return NIL). There's no need for a return statement since the last-evaluated expression in the function is the return value.</p>\n"}, {'answer_id': 19139, 'author': 'Patrick', 'author_id': 429, 'author_profile': 'https://Stackoverflow.com/users/429', 'pm_score': 4, 'selected': False, 'text': '<p>An expression is something that returns a value, whereas a statement does not.</p>\n\n<p>For examples:</p>\n\n<pre><code>1 + 2 * 4 * foo.bar()     //Expression\nfoo.voidFunc(1);          //Statement\n</code></pre>\n\n<p>The Big Deal between the two is that you can chain expressions together, whereas statements cannot be chained.</p>\n'}, {'answer_id': 19144, 'author': 'Matthew Schinckel', 'author_id': 188, 'author_profile': 'https://Stackoverflow.com/users/188', 'pm_score': 3, 'selected': False, 'text': "<p>Simply: an expression evaluates to a value, a statement doesn't.</p>\n"}, {'answer_id': 19150, 'author': 'Mike Stone', 'author_id': 122, 'author_profile': 'https://Stackoverflow.com/users/122', 'pm_score': 4, 'selected': False, 'text': '<p>You can find this on <a href="http://en.wikipedia.org/wiki/Statement_%28programming%29" rel="noreferrer">wikipedia</a>, but expressions are evaluated to some value, while statements have no evaluated value.</p>\n\n<p>Thus, expressions can be used in statements, but not the other way around.</p>\n\n<p>Note that some languages (such as Lisp, and I believe Ruby, and many others) do not differentiate statement vs expression... in such languages, everything is an expression and can be chained with other expressions.</p>\n'}, {'answer_id': 19224, 'author': 'Joel Spolsky', 'author_id': 4, 'author_profile': 'https://Stackoverflow.com/users/4', 'pm_score': 10, 'selected': True, 'text': '<p><strong>Expression:</strong> Something which evaluates to a value. Example: <em>1+2/x</em><br>\n<strong>Statement:</strong> A line of code which does something. Example: <em>GOTO 100</em></p>\n\n<p>In the earliest general-purpose programming languages, like FORTRAN, the distinction was crystal-clear. In FORTRAN, a statement was one unit of execution, a thing that you did. The only reason it wasn\'t called a "line" was because sometimes it spanned multiple lines. An expression on its own couldn\'t do anything... you had to assign it to a variable.</p>\n\n<pre><code>1 + 2 / X\n</code></pre>\n\n<p>is an error in FORTRAN, because it doesn\'t do anything. You had to do something with that expression:</p>\n\n<pre><code>X = 1 + 2 / X\n</code></pre>\n\n<p>FORTRAN didn\'t have a grammar as we know it today&mdash;that idea was invented, along with Backus-Naur Form (BNF), as part of the definition of Algol-60.  At that point the <em>semantic</em> distinction ("have a value" versus "do something") was enshrined in <em>syntax</em>: one kind of phrase was an expression, and another was a statement, and the parser could tell them apart.</p>\n\n<p>Designers of later languages blurred the distinction: they allowed syntactic expressions to do things, and they allowed syntactic statements that had values.\nThe earliest popular language example that still survives is C. The designers of C realized that no harm was done if you were allowed to evaluate an expression and throw away the result. In C, every syntactic expression can be a made into a statement just by tacking a semicolon along the end:</p>\n\n<pre><code>1 + 2 / x;\n</code></pre>\n\n<p>is a totally legit statement even though absolutely nothing will happen.  Similarly, in C, an expression can have <em>side-effects</em>&mdash;it can change something.</p>\n\n<pre><code>1 + 2 / callfunc(12);\n</code></pre>\n\n<p>because <code>callfunc</code> might just do something useful.</p>\n\n<p>Once you allow any expression to be a statement, you might as well allow the assignment operator (=) inside expressions. That\'s why C lets you do things like</p>\n\n<pre><code>callfunc(x = 2);\n</code></pre>\n\n<p>This evaluates the expression x = 2 (assigning the value of 2 to x) and then passes that (the 2) to the function <code>callfunc</code>.</p>\n\n<p>This blurring of expressions and statements occurs in all the C-derivatives (C, C++, C#, and Java), which still have some statements (like <code>while</code>) but which allow almost any expression to be used as a statement (in C# only assignment, call, increment, and decrement expressions may be used as statements; see <a href="https://stackoverflow.com/a/20771/8554766">Scott Wisniewski\'s answer</a>).</p>\n\n<p>Having two "syntactic categories" (which is the technical name for the sort of thing statements and expressions are) can lead to duplication of effort.   For example, C has two forms of conditional, the statement form</p>\n\n<pre><code>if (E) S1; else S2;\n</code></pre>\n\n<p>and the expression form</p>\n\n<pre><code>E ? E1 : E2\n</code></pre>\n\n<p>And sometimes people <em>want</em> duplication that isn\'t there: in standard C, for example, only a statement can declare a new local variable&mdash;but this ability is useful enough that the \nGNU C compiler provides a GNU extension that enables an expression to declare a local variable as well.</p>\n\n<p>Designers of other languages didn\'t like this kind of duplication, and they saw early on that if expressions can have side effects as well as values, then the <em>syntactic</em> distinction between statements and expressions is not all that useful&mdash;so they got rid of it.  Haskell, Icon, Lisp, and ML are all languages that don\'t have syntactic statements&mdash;they only have expressions.  Even the class structured looping and conditional forms are considered expressions, and they have values&mdash;but not very interesting ones.</p>\n'}, {'answer_id': 19362, 'author': 'Mark Harrison', 'author_id': 116, 'author_profile': 'https://Stackoverflow.com/users/116', 'pm_score': 5, 'selected': False, 'text': '<ul>\n<li>an expression is anything that yields a value:  2 + 2</li>\n<li>a statement is one of the basic "blocks" of program execution.</li>\n</ul>\n\n<p>Note that in C, "=" is actually an operator, which does two things:</p>\n\n<ul>\n<li>returns the value of the right hand subexpression.</li>\n<li>copies the value of the right hand subexpression into the variable on the left hand side.</li>\n</ul>\n\n<p>Here\'s an extract from the ANSI C grammar.  You can see that C doesn\'t have many different kinds of statements... the majority of statements in a program are expression statements, i.e. an expression with a semicolon at the end.</p>\n\n<pre><code>statement\n    : labeled_statement\n    | compound_statement\n    | expression_statement\n    | selection_statement\n    | iteration_statement\n    | jump_statement\n    ;\n\nexpression_statement\n    : \';\'\n    | expression \';\'\n    ;\n</code></pre>\n\n<p><a href="http://www.lysator.liu.se/c/ANSI-C-grammar-y.html" rel="noreferrer">http://www.lysator.liu.se/c/ANSI-C-grammar-y.html</a></p>\n'}, {'answer_id': 379882, 'author': 'Community', 'author_id': -1, 'author_profile': 'https://Stackoverflow.com/users/-1', 'pm_score': 2, 'selected': False, 'text': '<p>Some things about expression based languages:</p>\n\n<hr>\n\n<p>Most important: Everything returns an value</p>\n\n<hr>\n\n<p>There is no difference between curly brackets and braces for delimiting code blocks and expressions, since everything is an expression. This doesn\'t prevent lexical scoping though: A local variable could be defined for the expression in which its definition is contained and all statements contained within that, for example.</p>\n\n<hr>\n\n<p>In an expression based language, everything returns a value. This can be a bit strange at first -- What does <code>(FOR i = 1 TO 10 DO (print i))</code> return? </p>\n\n<p>Some simple examples:</p>\n\n<ul>\n<li><code>(1)</code> returns <code>1</code></li>\n<li><code>(1 + 1)</code> returns <code>2</code></li>\n<li><code>(1 == 1)</code> returns <code>TRUE</code></li>\n<li><code>(1 == 2)</code> returns <code>FALSE</code></li>\n<li><code>(IF 1 == 1 THEN 10 ELSE 5)</code> returns <code>10</code></li>\n<li><code>(IF 1 == 2 THEN 10 ELSE 5)</code> returns <code>5</code></li>\n</ul>\n\n<p>A couple more complex examples:</p>\n\n<ul>\n<li>Some things, such as some function calls, don\'t really have a meaningful value to return (Things that only produce side effects?). Calling  <code>OpenADoor(), FlushTheToilet()</code> or <code>TwiddleYourThumbs()</code> will return some sort of mundane value, such as OK, Done, or Success.</li>\n<li>When multiple unlinked expressions are evaluated within one larger expression, the value of the last thing evaluated in the large expression becomes the value of the large expression. To take the example of <code>(FOR i = 1 TO 10 DO (print i))</code>, the value of the for loop is "10", it causes the <code>(print i)</code> expression to be evaluated 10 times, each time returning i as a string. The final time through returns <code>10</code>, our final answer</li>\n</ul>\n\n<hr>\n\n<p>It often requires a slight change of mindset to get the most out of an expression based language, since the fact that everything is an expression makes it possible to \'inline\' a lot of things</p>\n\n<p>As a quick example:</p>\n\n<blockquote>\n<pre><code> FOR i = 1 to (IF MyString == "Hello, World!" THEN 10 ELSE 5) DO\n (\n    LotsOfCode\n )\n</code></pre>\n</blockquote>\n\n<p>is a perfectly valid replacement for the non expression-based</p>\n\n<blockquote>\n<pre><code>IF MyString == "Hello, World!" THEN TempVar = 10 ELSE TempVar = 5 \nFOR i = 1 TO TempVar DO\n(    \n    LotsOfCode  \n)\n</code></pre>\n</blockquote>\n\n<p>In some cases, the layout that expression-based code permits feels much more natural to me</p>\n\n<p>Of course, this can lead to madness. As part of a hobby project in an expression-based scripting language called MaxScript, I managed to come up with this monster line</p>\n\n<pre><code>IF FindSectionStart "rigidifiers" != 0 THEN FOR i = 1 TO (local rigidifier_array = (FOR i = (local NodeStart = FindsectionStart "rigidifiers" + 1) TO (FindSectionEnd(NodeStart) - 1) collect full_array[i])).count DO\n(\n    LotsOfCode\n)\n</code></pre>\n'}, {'answer_id': 646331, 'author': 'Daniel Earwicker', 'author_id': 27423, 'author_profile': 'https://Stackoverflow.com/users/27423', 'pm_score': 2, 'selected': False, 'text': "<p>A statement is a special case of an expression, one with <code>void</code> type. The tendency of languages to treat statements differently often causes problems, and it would be better if they were properly generalized.</p>\n\n<p>For example, in C# we have the very useful <code>Func&lt;T1, T2, T3, TResult&gt;</code> overloaded set of generic delegates. But we also have to have a corresponding <code>Action&lt;T1, T2, T3&gt;</code> set as well, and general purpose higher-order programming constantly has to be duplicated to deal with this unfortunate bifurcation.</p>\n\n<p>Trivial example - a function that checks whether a reference is null before calling onto another function:</p>\n\n<pre><code>TResult IfNotNull&lt;TValue, TResult&gt;(TValue value, Func&lt;TValue, TResult&gt; func)\n                  where TValue : class\n{\n    return (value == null) ? default(TValue) : func(value);\n}\n</code></pre>\n\n<p>Could the compiler deal with the possibility of <code>TResult</code> being <code>void</code>? Yes. All it has to do is require that return is followed by an expression that is of type <code>void</code>. The result of <code>default(void)</code> would be of type <code>void</code>, and the func being passed in would need to be of the form <code>Func&lt;TValue, void&gt;</code> (which would be equivalent to <code>Action&lt;TValue&gt;</code>).</p>\n\n<p>A number of other answers imply that you can't chain statements like you can with expressions, but I'm not sure where this idea comes from. We can think of the <code>;</code> that appears after statements as a binary infix operator, taking two expressions of type <code>void</code> and combining them into a single expression of type <code>void</code>.</p>\n"}, {'answer_id': 1035106, 'author': 'Conal', 'author_id': 127335, 'author_profile': 'https://Stackoverflow.com/users/127335', 'pm_score': 3, 'selected': False, 'text': '<p>For an explanation of important differences in composability (chainability) of expressions vs statements, my favorite reference is John Backus\'s Turing award paper, <em><a href="http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.130.4539&amp;rep=rep1&amp;type=pdf" rel="noreferrer">Can programming be liberated from the von Neumann style?</a></em>.</p>\n\n<p>Imperative languages (Fortran, C, Java, ...) emphasize statements for structuring programs, and have expressions as a sort of after-thought.  Functional languages emphasize expressions.  <em>Purely</em> functional languages have such powerful expressions than statements can be eliminated altogether.</p>\n'}, {'answer_id': 5439795, 'author': 'ncmathsadist', 'author_id': 467379, 'author_profile': 'https://Stackoverflow.com/users/467379', 'pm_score': 0, 'selected': False, 'text': '<p>Statements are grammatically complete sentences.  Expressions are not.  For example</p>\n\n<pre><code>x = 5\n</code></pre>\n\n<p>reads as "x gets 5."  This is a complete sentence.  The code</p>\n\n<pre><code>(x + 5)/9.0\n</code></pre>\n\n<p>reads, "x plus 5 all divided by 9.0."  This is not a complete sentence.  The statement</p>\n\n<pre><code>while k &lt; 10: \n    print k\n    k += 1\n</code></pre>\n\n<p>is a complete sentence. Notice that the loop header is not; "while k &lt; 10," is a subordinating clause.</p>\n'}, {'answer_id': 8450398, 'author': 'Shelby Moore III', 'author_id': 615784, 'author_profile': 'https://Stackoverflow.com/users/615784', 'pm_score': -1, 'selected': False, 'text': '<p>Most precisely, a statement must have a <strong>&quot;side-effect&quot;</strong> (i.e. <a href="https://stackoverflow.com/questions/602444/what-is-functional-declarative-and-imperative-programming/8357604#8357604">be imperative</a>) and an expression must <em>have</em> a <strong>value</strong> type (i.e. not the bottom type).</p>\n<p>The <a href="http://james-iry.blogspot.com/2009/08/getting-to-bottom-of-nothing-at-all.html" rel="nofollow noreferrer">type of a statement</a> is the unit type, but due to Halting theorem unit is fiction so lets say the <a href="https://stackoverflow.com/a/8450076/615784">bottom type</a>.</p>\n<hr />\n<p><code>Void</code> is not precisely the bottom type (it isn\'t the subtype of all possible types). It exists in languages that <a href="http://james-iry.blogspot.com/2009/08/getting-to-bottom-of-nothing-at-all.html" rel="nofollow noreferrer">don\'t have a completely sound type system</a>. That may sound like a snobbish statement, but completeness <a href="https://stackoverflow.com/a/8438947/615784">such as variance annotations</a> are critical to writing extensible software.</p>\n<p>Let\'s see what Wikipedia has to say on this matter.</p>\n<p><a href="https://en.wikipedia.org/wiki/Statement_(computer_science)" rel="nofollow noreferrer">https://en.wikipedia.org/wiki/Statement_(computer_science)</a></p>\n<blockquote>\n<p>In computer programming a statement is the smallest standalone element of an <strong>imperative</strong> programming language that expresses <strong>some action</strong> to be carried out.</p>\n<p>Many languages (e.g. C) make a distinction between statements and definitions, with a statement only containing executable code and a definition declaring an identifier, while an expression evaluates to a value only.</p>\n</blockquote>\n'}, {'answer_id': 12285190, 'author': 'Andaquin', 'author_id': 1038008, 'author_profile': 'https://Stackoverflow.com/users/1038008', 'pm_score': 2, 'selected': False, 'text': "<p>Statements -> Instructions to follow sequentially<br/>\nExpressions -> Evaluation that returns a value</p>\n\n<p>Statements are basically like steps, or instructions in an algorithm, the result of the execution of a statement is the actualization of the instruction pointer (so-called in assembler)</p>\n\n<p>Expressions do not imply and execution order at first sight, their purpose is to evaluate and return a value. In the imperative programming languages the evaluation of an expression has an order, but it is just because of the imperative model, but it is not their essence.</p>\n\n<p>Examples of Statements:</p>\n\n<pre><code>for\ngoto\nreturn\nif\n</code></pre>\n\n<p>(all of them imply the advance of the line (statement) of execution to another line)</p>\n\n<p>Example of expressions:</p>\n\n<pre><code>2+2\n</code></pre>\n\n<p>(it doesn't imply the idea of execution, but of the evaluation)</p>\n"}, {'answer_id': 12458901, 'author': 'Sujit', 'author_id': 792713, 'author_profile': 'https://Stackoverflow.com/users/792713', 'pm_score': 1, 'selected': False, 'text': '<p><strong><a href="http://msdn.microsoft.com/en-us/library/ms173143%28v=vs.80%29.aspx" rel="nofollow">Statement</a>,</strong></p>\n\n<p>A statement is a procedural building-block from which all C# programs are constructed. A statement can declare a local variable or constant, call a method, create an object, or assign a value to a variable, property, or field.</p>\n\n<p>A series of statements surrounded by curly braces form a block of code. A method body is one example of a code block.</p>\n\n<pre><code>bool IsPositive(int number)\n{\n    if (number &gt; 0)\n    {\n        return true;\n    }\n    else\n    {\n        return false;\n    }\n}\n</code></pre>\n\n<p>Statements in C# often contain expressions. An expression in C# is a fragment of code containing a literal value, a simple name, or an operator and its operands.</p>\n\n<p><strong><a href="http://msdn.microsoft.com/en-us/library/ms173144%28v=vs.80%29.aspx" rel="nofollow">Expression</a>,</strong></p>\n\n<p>An expression is a fragment of code that can be evaluated to a single value, object, method, or namespace. The two simplest types of expressions are literals and simple names. A literal is a constant value that has no name.</p>\n\n<pre><code>int i = 5;\nstring s = "Hello World";\n</code></pre>\n\n<p>Both i and s are simple names identifying local variables. When those variables are used in an expression, the value of the variable is retrieved and used for the expression.</p>\n'}, {'answer_id': 16422689, 'author': 'vfclists', 'author_id': 172406, 'author_profile': 'https://Stackoverflow.com/users/172406', 'pm_score': 1, 'selected': False, 'text': "<p>I prefer the meaning of <code>statement</code> in the formal logic sense of the word. It is one that changes the state of one or more of the variables in the computation, enabling a true or false statement to be made about their value(s).</p>\n\n<p>I guess there will always be confusion in the computing world and science in general when new terminology or words are introduced, existing words are 'repurposed' or users are ignorant of the existing, established or 'proper' terminology for what they are describing</p>\n"}, {'answer_id': 25722497, 'author': 'MadNik', 'author_id': 1239426, 'author_profile': 'https://Stackoverflow.com/users/1239426', 'pm_score': 1, 'selected': False, 'text': '<p>Here is the summery of one of the simplest answer I found.</p>\n\n<p>originally Answered by Anders Kaseorg</p>\n\n<p>A statement is a complete line of code that performs some action, while an expression is any section of the code that evaluates to a value. </p>\n\n<p><strong>Expressions can be combined “horizontally” into larger expressions using operators, while statements can only be combined “vertically” by writing one after another, or with block constructs.</strong> </p>\n\n<p>Every expression can be used as a statement (whose effect is to evaluate the expression and ignore the resulting value), but most statements cannot be used as expressions.</p>\n\n<p><a href="http://www.quora.com/Python-programming-language-1/Whats-the-difference-between-a-statement-and-an-expression-in-Python" rel="nofollow">http://www.quora.com/Python-programming-language-1/Whats-the-difference-between-a-statement-and-an-expression-in-Python</a></p>\n'}, {'answer_id': 30960293, 'author': 'Ely', 'author_id': 1566187, 'author_profile': 'https://Stackoverflow.com/users/1566187', 'pm_score': 2, 'selected': False, 'text': '<p>I am not really satisfied with any of the answers here. I looked at the grammar for <a href="http://slps.github.io/zoo/cpp/iso-n2723.html" rel="nofollow">C++ (ISO 2008)</a>. However maybe for the sake of didactics and programming the answers might suffice to distinguish the two elements (reality looks more complicated though).</p>\n\n<p>A statement consists of zero or more expressions, but can also be other language concepts. This is the Extended Backus Naur form for the grammar (excerpt for statement):</p>\n\n<pre><code>statement:\n        labeled-statement\n        expression-statement &lt;-- can be zero or more expressions\n        compound-statement\n        selection-statement\n        iteration-statement\n        jump-statement\n        declaration-statement\n        try-block\n</code></pre>\n\n<p>We can see the other concepts that are considered statements in C++.</p>\n\n<ul>\n<li><em>expression-statement</em>s is self-explaining (a statement can consist of zero or <em>more</em> expressions, read the grammar carefully, it\'s tricky) </li>\n<li><code>case</code> for example is a <em>labeled-statement</em></li>\n<li><em>selection-statement</em>s are <code>if</code> <code>if/else</code>, <code>case</code></li>\n<li><em>iteration-statement</em>s are <code>while</code>, <code>do...while</code>, <code>for (...)</code></li>\n<li><em>jump-statement</em>s are <code>break</code>, <code>continue</code>, <code>return</code> (can return expression), <code>goto</code></li>\n<li><em>declaration-statement</em> is the set of declarations</li>\n<li><em>try-block</em> is statement representing <code>try/catch</code> blocks</li>\n<li><em>and there might be some more down the grammar</em></li>\n</ul>\n\n<p>This is an excerpt showing the expressions part:</p>\n\n<pre><code>expression:\n        assignment-expression\n        expression "," assignment-expression\nassignment-expression:\n        conditional-expression\n        logical-or-expression assignment-operator initializer-clause\n        throw-expression\n</code></pre>\n\n<ul>\n<li>expressions are or contain often assignments</li>\n<li><em>conditional-expression</em> (sounds misleading) refers to usage of the operators (<code>+</code>, <code>-</code>, <code>*</code>, <code>/</code>, <code>&amp;</code>, <code>|</code>, <code>&amp;&amp;</code>, <code>||</code>, ...)</li>\n<li><em>throw-expression</em> - uh? the <code>throw</code> clause is an expression too</li>\n</ul>\n'}, {'answer_id': 32057203, 'author': 'Shelby Moore III', 'author_id': 615784, 'author_profile': 'https://Stackoverflow.com/users/615784', 'pm_score': -1, 'selected': False, 'text': "<p>To improve on and validate my prior answer, definitions of programming language terms should be explained from computer science type theory when applicable.</p>\n\n<p>An expression has a type other than the Bottom type, i.e. it has a value. A statement has the Unit or Bottom type.</p>\n\n<p>From this it follows that a statement can only have any effect in a program when it creates a side-effect, because it either can not return a value or it only returns the value of the Unit type which is either nonassignable (in some languages such a C's <code>void</code>) or (such as in Scala) can be stored for a delayed evaluation of the statement.</p>\n\n<p>Obviously a <code>@pragma</code> or a <code>/*comment*/</code> have no type and thus are differentiated from statements. Thus the only type of statement that would have no side-effects would be a non-operation. Non-operation is only useful as a placeholder for future side-effects. Any other action due to a statement would be a side-effect. Again a compiler hint, e.g. <code>@pragma</code>, is not a statement because it has no type.</p>\n"}, {'answer_id': 57619680, 'author': 'FrankHB', 'author_id': 2307646, 'author_profile': 'https://Stackoverflow.com/users/2307646', 'pm_score': 2, 'selected': False, 'text': '<p>The de-facto basis of these concepts is:</p>\n\n<p><strong>Expressions</strong>: A syntactic category whose instance can be evaluated to a value.</p>\n\n<p><strong>Statement</strong>: A syntactic category whose instance may be involved with evaluations of an expression and the resulted value of the evaluation (if any) is not guaranteed available.</p>\n\n<p>Besides to the very initial context for FORTRAN in the early decades, both definitions of expressions and statements in the accepted answer are obviously wrong:</p>\n\n<ul>\n<li>Expressions can be unvaluated operands. Values are never produced from them.\n\n<ul>\n<li>Subexpressions in non-strict evaluations can be definitely unevaluated.\n\n<ul>\n<li>Most C-like languages have the so-called <a href="https://en.wikipedia.org/wiki/Short-circuit_evaluation" rel="nofollow noreferrer">short-circuit evaluation</a> rules to conditionally skip some subexpression evaluations not change the final result in spite of the side effects.</li>\n</ul></li>\n<li>C and some C-like languages have the notion of unevaluated operand which may be even normatively defined in the language specification. Such constructs are used to avoid the evaluations definitely, so the remained context information (e.g. types or alignment requirements) can be statically distinguished without changing the behavior after the program translation.\n\n<ul>\n<li>For example, an expression used as the operand of the <code>sizeof</code> operator is never evaluated.</li>\n</ul></li>\n</ul></li>\n<li>Statements have nothing to do with line constructs. They can do something more than expressions, depending on the language specifications.\n\n<ul>\n<li>Modern Fortran, as the direct descendant of the old FORTRAN, has concepts of <em>executable statement</em>s and <em>nonexecutable statement</em>s.</li>\n<li>Similarly, C++ defines declarations as the top-level subcategory of a translation unit. A declaration in C++ is a statement. <sub>(This is not true in C.)</sub> There are also <em>expression-statement</em>s like Fortran\'s executable statements.</li>\n<li>To the interest of the comparison with expressions, only the "executable" statements matter. But you can\'t ignore the fact that statements are already generalized to be constructs forming the translation units in such imperative languages. So, as you can see, the definitions of the category vary a lot. The (probably) only remained common property preserved among these languages is that <strong>statements are expected to be interpreted in the lexical order</strong> (for most users, left-to-right and top-to-bottom).</li>\n</ul></li>\n</ul>\n\n<p><sub>(BTW, I want to add [citation needed] to that answer concerning materials about C because I can\'t recall whether DMR has such opinions. It seems not, otherwise there should be no reasons to preserve the functionality duplication in the design of C: notably, the comma operator vs. the statements.)</sub></p>\n\n<p>(The following rationale is not the direct response to the original question, but I feel it necessary to clarify something already answered here.)</p>\n\n<p>Nevertheless, it is doubtful that we need a specific category of "statements" in general-purpose programming languages:</p>\n\n<ul>\n<li>Statements are not guaranteed to have more semantic capabilities over expressions in usual designs.\n\n<ul>\n<li>Many languages have already successfully abandon the notion of statements to get clean, neat and consistent overall designs.\n\n<ul>\n<li>In such languages, expressions can do everything old-style statements can do: just drop the unused results when the expressions are evaluated, either by leaving the results explicitly unspecified (e.g. in R<sup>n</sup>RS Scheme), or having a special value (as a value of a unit type) not producible from normal expression evaluations.</li>\n<li>The lexical order rules of evaluation of expressions can be replaced by explicit sequence control operator (e.g. <code>begin</code> in Scheme) or syntactic sugar of monadic structures.</li>\n<li>The lexical order rules of other kinds of "statements" can be derived as syntactic extensions (using hygienic macros, for example) to get the similar syntactic functionality. (And it can actually <a href="https://en.wikipedia.org/wiki/Fexpr" rel="nofollow noreferrer">do more</a>.)</li>\n</ul></li>\n<li>On the contrary, statements cannot have such conventional rules, because they don\'t compose on evaluation: there is just no such common notion of "substatement evaluation". <sub>(Even if any, I doubt there can be something much more than copy and paste from existed rules of evaluation of expressions.)</sub> \n\n<ul>\n<li>Typically, languages preserving statements will also have expressions to express computations, and there is a top-level subcategory of the statements preserved to expression evaluations for that subcategory. For example, C++ has the so-called <em>expression-statement</em> as the subcategory, and uses the <em>discarded-value expression</em> evaluation rules to specify the general cases of full-expression evaluations in such context. Some languages like C# chooses to refine the contexts to simplify the use cases, but it bloats the specification more.</li>\n</ul></li>\n</ul></li>\n<li>For users of programming languages, the significance of statements may confuse them further.\n\n<ul>\n<li>The separation of rules of expressions and statements in the languages requires more effort to learn a language.</li>\n<li>The naive lexical order interpretation hides the more important notion: expression evaluation. (This is probably most problematic over all.)\n\n<ul>\n<li>Even the evaluations of full expressions in statements are constraint with the lexical order, subexpressions are not (necessarily). Users should ultimately learn this besides any rules coupled to the statements. (Consider how to make a newbie get the point that <code>++i + ++i</code> is meaningless in C.)</li>\n<li>Some languages like Java and C# further constraints the order of evaluations of subexpressions to be permissive of ignorance of evaluation rules. It can be even more problematic.\n\n<ul>\n<li>This seems overspecified to users who have already learned the idea of expression evaluation. It also encourages the user community to follow the blurred mental model of the language design.</li>\n<li>It bloats the language specification even more.</li>\n<li>It is harmful to optimization by missing the expressiveness of nondeterminism on evaluations, before more complicated primitives are introduced.</li>\n</ul></li>\n<li>A few languages like C++ (particularly, C++17) specify more subtle contexts of evaluation rules, as a compromise of the problems above.\n\n<ul>\n<li>It bloats the language specification a lot.</li>\n<li>This goes totally against to simplicity to average users...</li>\n</ul></li>\n</ul></li>\n</ul></li>\n</ul>\n\n<p>So why statements? Anyway, the history is already a mess. It seems most language designers do not take their choice carefully.</p>\n\n<p>Worse, it even gives some type system enthusiasts (who are not familiar enough with the PL history) some misconceptions that type systems must have important things to do with the more essential designs of rules on the operational semantics.</p>\n\n<p>Seriously, reasoning depending on types are not that bad in many cases, but particularly not constructive in this special one. Even experts can screw things up.</p>\n\n<p>For example, someone emphasizes the well-typing nature <a href="http://okmij.org/ftp/continuations/undelimited.html#introduction" rel="nofollow noreferrer">as the central argument against the traditional treatment of undelimited continuations</a>. Although the conclusion is somewhat reasonable and the insights about composed functions are OK (<a href="http://fexpr.blogspot.com/2014/03/continuations-and-term-rewriting-calculi.html" rel="nofollow noreferrer">but still far too naive to the essense</a>), this argument is not sound because it totally ignores the "side channel" approach in practice like <code>_Noreturn any_of_returnable_types</code> (in C11) to encode <code>Falsum</code>.  <sub>And strictly speaking, an abstract machine with unpredictable state is not identical to "a crashed computer".</sub></p>\n'}, {'answer_id': 62324086, 'author': 'Xwtek', 'author_id': 5784051, 'author_profile': 'https://Stackoverflow.com/users/5784051', 'pm_score': 0, 'selected': False, 'text': '<p>In a statement-oriented programming language, a code block is defined as a list of statements. In other words, a statement is a piece of syntax that you can put inside a code block without causing a syntax error.</p>\n\n<p>Wikipedia defines the word statement similarly</p>\n\n<blockquote>\n  <p>In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements</p>\n</blockquote>\n\n<p>Notice the latter statement. (although "a program" in this case is technically wrong because both C and Java reject a program that consists of nothing of statements.)</p>\n\n<p>Wikipedia defines the word expression as </p>\n\n<blockquote>\n  <p>An expression in a programming language is a syntactic entity that may be evaluated to determine its value</p>\n</blockquote>\n\n<p>This is, however, false, because in Kotlin, <code>throw new Exception("")</code> is an expression but when evaluated, it simply throws an exception, never returning any value.</p>\n\n<p>In a statically typed programming language, every expression has a type. This definition, however, doesn\'t work in a dynamically typed programming language.</p>\n\n<p>Personally, I define an expression as a piece of syntax that can be composed with an operator or function calls to yield a bigger expression. This is actually similar to the explanation of expression by Wikipedia:</p>\n\n<blockquote>\n  <p>It is a combination of one or more constants, variables, functions, and operators that the programming language interprets (according to its particular rules of precedence and of association) and computes to produce ("to return", in a stateful environment) another value</p>\n</blockquote>\n\n<p>But, the problem is in C programming language, given a function executeSomething like this:</p>\n\n<pre><code>void executeSomething(void){\n    return;\n}\n</code></pre>\n\n<p>Is <code>executeSomething()</code> an expression or is it a statement? According to my definition, it is a statement because as defined in Microsoft\'s C reference grammar, </p>\n\n<blockquote>\n  <p>You cannot use the (nonexistent) value of an expression that has type void in any way, nor can you convert a void expression (by implicit or explicit conversion) to any type except void</p>\n</blockquote>\n\n<p>But the same page clearly indicates that such syntax is an expression.</p>\n'}, {'answer_id': 63378331, 'author': 'Gk Mohammad Emon', 'author_id': 7200133, 'author_profile': 'https://Stackoverflow.com/users/7200133', 'pm_score': 0, 'selected': False, 'text': "<p>A <strong>statement</strong> is a block of code that doesn't return anything and which is just a standalone unit of execution. For example-</p>\n<pre><code>if(a&gt;=0)\nprintf(&quot;Hello Humen,I'm a statement&quot;);\n</code></pre>\n<p>An <strong>expression</strong>, on the other hand, returns or evaluates a new value. For example -</p>\n<pre><code> if(a&gt;=0)\n    return a+10;//This is an expression because it evalutes an new value;\n</code></pre>\n<p>or</p>\n<pre><code> a=10+y;//This is also an expression because it returns a new value. \n</code></pre>\n"}, {'answer_id': 63503616, 'author': 'Vlad Bezden', 'author_id': 30038, 'author_profile': 'https://Stackoverflow.com/users/30038', 'pm_score': 0, 'selected': False, 'text': '<p><a href="https://docs.python.org/3/glossary.html#term-expression" rel="nofollow noreferrer">Expression</a></p>\n<blockquote>\n<p>A piece of syntax which can be evaluated to some value. In other words, an expression is an accumulation of expression elements like literals, names, attribute access, operators or function calls which all return a value. In contrast to many other languages, not all language constructs are expressions. There are also statements which cannot be used as expressions, such as while. Assignments are also statements, not expressions.</p>\n</blockquote>\n<p><a href="https://docs.python.org/3/glossary.html#term-statement" rel="nofollow noreferrer">Statement</a></p>\n<blockquote>\n<p>A statement is part of a suite (a “block” of code). A statement is either an expression or one of several constructs with a keyword, such as if, while or for.</p>\n</blockquote>\n'}]
['https://Stackoverflow.com/questions/19132', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/-1/']