Skip to content

Commit 496c421

Browse files
committed
Move explanation of scopes to blocks slide
Which was, confusingly, already named "Blocks and Scopes".
1 parent 0f94b20 commit 496c421

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

src/control-flow-basics/blocks-and-scopes.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ minutes: 5
44

55
# Blocks and Scopes
66

7-
## Blocks
8-
97
A block in Rust contains a sequence of expressions, enclosed by braces `{}`.
108
Each block has a value and a type, which are those of the last expression of the
119
block:
@@ -19,14 +17,22 @@ fn main() {
1917
z - y
2018
};
2119
println!("x: {x}");
20+
// println!("y: {y}");
2221
}
2322
```
2423

2524
If the last expression ends with `;`, then the resulting value and type is `()`.
2625

26+
A variable's scope is limited to the enclosing block.
27+
2728
<details>
2829

2930
- You can show how the value of the block changes by changing the last line in
3031
the block. For instance, adding/removing a semicolon or using a `return`.
3132

33+
- Demonstrate that attempting to access `y` outside of its scope won't compile.
34+
35+
- Values are effectively "deallocated" when they go out of their scope, even if
36+
their data on the stack is still there.
37+
3238
</details>

0 commit comments

Comments
 (0)