Why background() is not updated in a draw() loop

I start with Processing.

I’m studying Daniel Shiffman’s book “Learning Processing”.

In Exercise 6.5 of the book, I can not understand why background(0) which is in draw() is not updated each time a new line is drawn, erasing the previously drawn line, but only when endY returns to 0 at the end, in if(endY > height) …

int endY;

void setup() {
  size(200, 200);
  frameRate(5);
  
  endY = 0;
}

void draw() {
  background(0);
  
  for (int y = 0; y < endY; y += 10) {
    stroke(255);
    line(0, y, width, y);
  }
  endY = endY + 10;
  
  if(endY > height) {
    endY = 0;
  }
}

It’s not very clear to me. Could someone explain to me?

in the case you want only one line,
and that is moving down,
the code could be much more simple

int endY=0;

void setup() {
  size(200, 200);
  frameRate(5);
  stroke(255);
}

void draw() {
  background(0);
  //text(nf(frameRate,1,1),10,9);
  //  for (int y = 0; y < endY; y += 10)  line(0, y, width, y);
  line(0, endY, width, endY);
  endY = endY + 10;
  if (endY > height) endY = 0;
}

because now you ( after background(0) == CLEAR )
draw by a FOR loop as many lines as “endY” allows.
hm, where the FOR loop comes from? not from:

Well… it’s Exercise 6.5, not Example 6.5
http://learningprocessing.com/exercises/chp06/exercise-06-05-one-line-at-a-time

And thank you for your explanation, it’s a little clearer for me … I hope …

// rendering one line at a time using a for loop.

ok, i might have expected same like you.