Communities

Writing
Writing
Codidact Meta
Codidact Meta
The Great Outdoors
The Great Outdoors
Photography & Video
Photography & Video
Scientific Speculation
Scientific Speculation
Cooking
Cooking
Electrical Engineering
Electrical Engineering
Judaism
Judaism
Languages & Linguistics
Languages & Linguistics
Software Development
Software Development
Mathematics
Mathematics
Christianity
Christianity
Code Golf
Code Golf
Music
Music
Physics
Physics
Linux Systems
Linux Systems
Power Users
Power Users
Tabletop RPGs
Tabletop RPGs
Community Proposals
Community Proposals
tag:snake search within a tag
answers:0 unanswered questions
user:xxxx search by author id
score:0.5 posts with 0.5+ score
"snake oil" exact phrase
votes:4 posts with 4+ votes
created:<1w created < 1 week ago
post_type:xxxx type of post
Search help
Notifications
Mark all as read See all your notifications »
Q&A

Welcome to Software Development on Codidact!

Will you help us build our independent community of developers helping developers? We're small and trying to grow. We welcome questions about all aspects of software development, from design to code to QA and more. Got questions? Got answers? Got code you'd like someone to review? Please join us.

Post History

75%
+7 −1
Q&A What are statements and expressions?

In computer programming, an expression is something that yields a value. A statement performs an action. For example, let us look at some pseudocode. Let's assume that we want to calculate the su...

posted 1y ago by FractionalRadix‭

Answer
#1: Initial revision by user avatar FractionalRadix‭ · 2023-08-04T07:54:21Z (over 1 year ago)
In computer programming, an _expression_ is something that yields a value. 

A _statement_ performs an action.

For example, let us look at some pseudocode. Let's assume that we want to calculate the sum of 3 variables:

    sum = a + b + c;
    print(sum);

`print(sum);` is a statement: it performs an action.  
`a + b + c` is an expression: it yields a value.

Now you may be wondering: is `sum = a + b + c` a statement, or an expression?  
The answer is that it's a statement, but it _contains_ an expression. `a + b + c` yields a value, and then an action is taken: the value is assigned to a variable.  

In this example, we have an arithmetic expression. But most operations on strings and booleans are also expressions!  
For example, we could have a conditional:
     `if (a > 3 && p == 5) { ...  }`
In this condition statement, the part `a > 3 && p == 5` is an expression. A boolean expression.

Or, we might be concatenating strings:

   fullName = firstName + " " + lastName;

In this line of code, `firstName + " " + lastName` is a string expression. It yields a value. The line as a whole is a statement: it evaluates an expression and stores the result in a new variable.

In general, expressions occur inside statements. An expression yields a value, but after you have your value, you'll want to do something with it - store it somewhere, or output it, or send it as an argument to another function.