Statement vs Expression
A statement does a job, like storing a value. An expression only works out a value, and a statement then uses it.
Statement
One whole step in a program. Each is like a line on a to-do list.
A statement is one complete step that tells the computer to do something. It might keep a value, show a word or add two numbers. In many languages each statement sits on its own line. The computer runs statements one after another, from top to bottom. Some statements hold others inside them, like a loop or an if.
Expression
A piece of code that works out to one value, like 3 + 4.
An expression is a piece of code that works out to a value. 3 + 4 is an expression, and its value is 7. A name of a variable is an expression too, and so is a question like age > 10. The computer works out the value, then uses it. Expressions often sit inside statements, the way a sum sits inside a sentence.
In one line
- Statement
- One whole step in a program. Each is like a line on a to-do list.
- Expression
- A piece of code that works out to one value, like 3 + 4.