Skip to content
Merged
Show file tree
Hide file tree
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
1 change: 0 additions & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
- [Solution](types-and-values/solution.md)
- [Control Flow Basics](control-flow-basics.md)
- [Blocks and Scopes](control-flow-basics/blocks-and-scopes.md)
- [Scopes and Shadowing](control-flow-basics/blocks-and-scopes/scopes.md)
- [`if` Expressions](control-flow-basics/if.md)
- [`match` Expressions](control-flow-basics/match.md)
- [Loops](control-flow-basics/loops.md)
Expand Down
10 changes: 8 additions & 2 deletions src/control-flow-basics/blocks-and-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ minutes: 5

# Blocks and Scopes

## Blocks

A block in Rust contains a sequence of expressions, enclosed by braces `{}`.
Each block has a value and a type, which are those of the last expression of the
block:
Expand All @@ -19,14 +17,22 @@ fn main() {
z - y
};
println!("x: {x}");
// println!("y: {y}");
}
```

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

A variable's scope is limited to the enclosing block.

<details>

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

- Demonstrate that attempting to access `y` outside of its scope won't compile.

- Values are effectively "deallocated" when they go out of their scope, even if
their data on the stack is still there.

</details>
35 changes: 0 additions & 35 deletions src/control-flow-basics/blocks-and-scopes/scopes.md

This file was deleted.