Sign a var value in a if statment

Im trying to sign a value if a condition is true, but im getting a scope error

use std::env;

fn main(){
    let args: Vec<String> = env::args().collect();

    if args.len() > 1{
        let to_print = &args[1];
    }
    else{
        println!(" Only a few arguments");
    }
    println!("{}", to_print);
}

getting this error
error[E0425]: cannot find value teste in this scope
–> src/main.rs:12:20
|
12 | println!("{}", teste);
| ^^^^^ not found in this scope

println!("{}", to_print); should be in the then branch of the if,after let to_print = &args[1];.

Working version:

use std::env;

fn main(){
    let args: Vec<String> = env::args().collect();

    if args.len() > 1{
        let to_print = &args[1];
        println!("{}", to_print);
    }else{
        println!(" Only a few arguments");
    }
}

thanks :wink:

{
    // scope/lifetime a

    if ... {
        // scope/lifetime b
    }

    // b < a, can't use b here 
}
  1. use it in the scope/lifetime b
  2. define it in scope/lifetime a or which > a