Re:Statements vs. Expressions
by bluetomcat on Thursday July 14, 2022 @07:03AM
(#32094360)
Generally, an expression returns a value and can be used as the operand of an operator, whereas a "statement" is the terminal "top-level" node that doesn't return a value and cannot therefore be nested.
What is sometimes confusing, is that some statements also double as expressions, that is, also return values; and that it also depends on the language. eg. the assignment statement returns a value in C and Javascript, but not in Go or Python;
Also depending on the language, expressions themselves may be valid statements. For example, this compiles in C; ;this is a valid python program: ;but if I try this in Go: