File tree Expand file tree Collapse file tree 3 files changed +8
-38
lines changed Expand file tree Collapse file tree 3 files changed +8
-38
lines changed Original file line number Diff line number Diff line change 3030    -  [ Solution] ( types-and-values/solution.md ) 
3131-  [ Control Flow Basics] ( control-flow-basics.md ) 
3232  -  [ Blocks and Scopes] ( control-flow-basics/blocks-and-scopes.md ) 
33-     -  [ Scopes and Shadowing] ( control-flow-basics/blocks-and-scopes/scopes.md ) 
3433  -  [ ` if `  Expressions] ( control-flow-basics/if.md ) 
3534  -  [ ` match `  Expressions] ( control-flow-basics/match.md ) 
3635  -  [ Loops] ( control-flow-basics/loops.md ) 
Original file line number Diff line number Diff line change @@ -4,8 +4,6 @@ minutes: 5
44
55# Blocks and Scopes  
66
7- ## Blocks  
8- 
97A block in Rust contains a sequence of expressions, enclosed by braces ` {} ` .
108Each block has a value and a type, which are those of the last expression of the
119block:
@@ -19,14 +17,22 @@ fn main() {
1917        z - y 
2018    }; 
2119    println!("x: {x}"); 
20+     // println!("y: {y}"); 
2221} 
2322``` 
2423
2524If 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 >
Load Diff This file was deleted. 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments