title: Declaring mutable variables outside loop gives errors
body: <p>As in <a href="https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html" rel="nofollow noreferrer">Programming a Guessing Game</a> in Rust, it is necessary that we declare the variable inside the loop as:</p>
  
  <pre><code>loop {
  let mut guess = String::new();
  ...
  }
  </code></pre>
  
  <p>But if this mutable variable is declared outside the loop it panics:</p>
  
  <pre><code>let mut guess = String::new();
  loop {
  ...
  }
  </code></pre>
  
  <p>The panic message printed is just:</p>
  
  <blockquote>
    <p>invalid digit found in string</p>
  </blockquote>
  
  <p>Why does this happen when the variable <code>guess</code> has been declared <code>mut</code> already?</p>
  
  <p>Here's the failing complete code: </p>
  
  <pre class="lang-rust prettyprint-override"><code>use rand::Rng;
  use std::cmp::Ordering;
  use std::io;
  
  fn main() {
      println!("Guess the number!");
  
      let secret_number = rand::thread_rng().gen_range(1, 101);
  
      let mut guess = String::new();
      loop {
          println!("Please input your guess.");
  
          io::stdin()
              .read_line(&amp;mut guess)
              .expect("Failed to read line");
  
          let guess: u32 = match guess.trim().parse() {
              Ok(num) =&gt; num,
              Err(e) =&gt; {
                  println!("{}", e);
                  continue;
              }
          };
  
          println!("You guessed: {}", guess);
  
          match guess.cmp(&amp;secret_number) {
              Ordering::Less =&gt; println!("Too small!"),
              Ordering::Greater =&gt; println!("Too big!"),
              Ordering::Equal =&gt; {
                  println!("You win!");
                  break;
              }
          }
      }
  }
  </code></pre>