LCD 20 x 4 scrollDisplayLeft/Right. Letters reappear in another row.

Hi friends,
I am working with the display LCD 20 x 4 and I have noticed an unexpected behavior when I use the instruction “scrollDisplayLeft ()” or “scrollDisplayRigh ()”. The problem is that the letters not disappear because they reappear in another row that I did not expect. What is it wrong with my code?
Thank you!

#include <Wire.h>
#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd(0x27, 20, 4);

void setup()
  lcd.setCursor(0, 2);
  lcd.print("Hello, world!");

void loop()

  for (int i = 0; i < 20; i++) {
    for (int i = 0; i < 20; i++) {

Nothing is wrong with your code. That is the way the hd44780 LCD display and memory works as it has very limited memory.
On a 20x4 display, you are seeing all the memory it has.
What is misleading and can be confusing is the LiquidCrystal library functions scrollDisplayRight() and scrollDisplayLeft()
The actual datasheet does not use the term "scroll" it uses the term "shift".

The way the h/w works is that it shifts the RAM location where the LCD starts displaying characters on the display.

The hd44780 has 80 bytes of internal RAM.
While it can vary a bit depending on how the LCD module is built and its geometry,
it is best to think of it as two 40 character rows/lines.
On a 16x2 display, you see the first 16 characters of each of the two 40 character lines.
If you do a shift, you start to see more of the 40 character line that was previously off the display.

In the case of 20x4 display, the characters you see is the entire RAM, so when you do a shift to move the starting RAM location, the characters on the display will appear to rotate around on the display.

--- bill

Thank you very much! You answer has been very useful!!

Check out the LCD Addressing link at Don's Collected Technical Information for more details.