Set a variable with Serial Arduino

i want something like

int i = 0;
void setup(){

void loop(){
  if(Serial.available()){ // if i input 1 to serial
    i = Serial.parseInt(); 
  Serial.println(i); // i want my variable is set to 1 and display a list of 1
                          // if Serial change to 2, my value will change and display a list of 2

I'm new with arduino and don't know the best way to do this :frowning:

Check out the Serial examples (under communication) included with the IDE