Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions src/ch03-01-variables-and-mutability.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,15 @@ use of the `let` keyword as follows:
```

This program first binds `x` to a value of `5`. Then, it creates a new variable
`x` by repeating `let x =`, taking the original value and adding `1` so that
the value of `x` is `6`. Then, within an inner scope created with the curly
brackets, the third `let` statement also shadows `x` and creates a new
variable, multiplying the previous value by `2` to give `x` a value of `12`.
When that scope is over, the inner shadowing ends and `x` returns to being `6`.
When we run this program, it will output the following:
that is also called `x`, by repeating `let x =`. The program takes the original
value of `x` and adds `1`, so that the value of the new variable `x` is now `6`.
It is important to understand that the right-hand side is evaluated first `(5 + 1)`
before this value is assigned to the new variable `x`. Then, within an inner
scope created with the curly brackets, the third let statement also shadows `x`
and creates a new variable, evaluating the right-hand side first `(6 * 2)`
before assigning `12` to the new `x`. When that scope is over, the inner
shadowing ends and `x` returns to being `6`. When we run this program, it will
output the following:

```console
{{#include ../listings/ch03-common-programming-concepts/no-listing-03-shadowing/output.txt}}
Expand Down