Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Statement (computer science)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
==Expressions== A distinction is often made between statements, which are executed, and [[expression (programming)|expression]]s, which are evaluated. Expressions always evaluate to a value, which statements do not. However, expressions are often used as part of a larger statement. In most programming languages, a statement can consist of little more than an expression, usually by following the expression with a statement terminator (semicolon). In such a case, while the expression evaluates to a value, the complete statement does not (the expression's value is discarded). For instance, in C, C++, C#, and many similar languages, <code>x = y + 1</code> is an expression that will set x to the value of y plus one, and the whole expression itself will evaluate to the same value that x is set to. However, <code>x = y + 1;</code> (note the semicolon at the end) is a statement that will still set x to the value of y plus one because the expression within the statement is still evaluated, but the result of the expression is discarded, and the statement itself does not evaluate to any value.<ref>{{Cite web |title=ISO/IEC 9899:1999 (E) |url=https://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf |url-status=live |archive-url=https://web.archive.org/web/20240207035551/http://www.dii.uchile.cl/~daespino/files/Iso_C_1999_definition.pdf |archive-date=Feb 7, 2024 |website=ISO/IEC}}</ref> Expressions can also be contained within other expressions. For instance, the expression <code>x = y + 1</code> contains the expression <code>y + 1</code>, which in turn contains the values <code>y</code> and <code>1</code>, which are also technically expressions. Although the previous examples show assignment expressions, some languages do not implement assignment as an expression, but rather as a statement. A notable example of this is [[Python (Programming Language)|Python]], where = is not an operator, but rather just a separator in the assignment statement. Although Python allows multiple assignments as each assignment were an expression, this is simply a special case of the assignment statement built into the language grammar rather than a true expression.<ref>{{cite web | url=https://docs.python.org/3/reference/simple_stmts.html#assignment-statements | title=7. Simple statements |work=Python 3.10.8 documentation }}</ref>
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)