Skip to content

Commit

Permalink
Clear up confusion about statements as expressions (#441)
Browse files Browse the repository at this point in the history
Issue #440 was discussed in today's sync call. I mentioned there that I think it's least confusing to just avoid saying "these are not statements" while still saying positively that "these are all expressions".

Resolves #440.
  • Loading branch information
jemc authored Jul 14, 2020
1 parent 33dd61c commit 125f3d4
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions content/expressions/control-structures.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ else
```
Here it is not obvious whether the `else` is an alternative to the first or the second `if`. In fact here the `else` relates to the `if(b)` so our example contains a bug. Pony avoids this type of bug by handling `if` and `else` differently and the need for `elseif` comes out of that.
## Everything is an expression
## Control structures are expressions
The big difference for control structures between Pony and other languages is that in Pony everything is an expression. In languages like C++ and Java `if` is a statement, not an expression. This means that you can't have an `if` inside an expression, there has to be a separate conditional operator '?'.
In Pony there are no statements, there are only expressions; everything hands back a value. Your `if` statement hands you back a value. Your `for` loop (which we'll get to a bit later) hands you back a value.
In Pony control flow statements like this are all expressions that hand back a value. Your `if` statement hands you back a value. Your `for` loop (which we'll get to a bit later) hands you back a value.
This means you can use `if` directly in a calculation:
Expand Down

0 comments on commit 125f3d4

Please sign in to comment.