According to Nim manual:

[https://nim-lang.org/docs/manual.html#statements-and-expressions-if-statement](https://nim-lang.org/docs/manual.html#statements-and-expressions-if-statement)

_In if statements new scopes begin immediately after the if /elif/else keywords 
and ends after the corresponding then block._

For example:
    
    
    if true:
      let foo = 1
    
    # Error: undeclared identifier: 'foo'
    echo foo
    
    Run

You can write shorter code by using if expression and tuple unpacking

[https://nim-lang.org/docs/manual.html#statements-and-expressions-if-expression](https://nim-lang.org/docs/manual.html#statements-and-expressions-if-expression)

[https://nim-lang.org/docs/manual.html#statements-and-expressions-tuple-unpacking](https://nim-lang.org/docs/manual.html#statements-and-expressions-tuple-unpacking)
    
    
    proc f(size=1) =
      let (widFrame, hiFrame)  = if size == 1: (320, 200) else: (3200, 2000)
      echo (widFrame, hiFrame)
    
    f(1)
    f(2)
    
    Run

Reply via email to