Trying to read multiple input lines (newbie question)

Hi there!

I just started learning Rust yesterday. I am trying to read stdin until the user says end.

use std::io;

fn main() {
let mut input = String::new();

while input != "end\n"{
    println!("Say something: ");
    io::stdin().read_line(&mut input).expect("failed to read line");
    println!("You said: {}", input);
}   

}

For some reason every new line of input just gets appended to the previous lines:

Say something:
one
You said: one

Say something:
two
You said: one
two

Say something:
end
You said: one
two
end

Say something:

Why does that happen? of course, i could declare input inside the while loop or something like that but I want to know why it behaves like this..

TIA,
Michi

As it's clearly stated in the docs:

It appends, it doesn't overwrite.

RTFM. Understood :smiley: