Why my LCD does not work with this if statement?
On the Uno, pin 0 and 1 are used for Serial. You can't use pin 1 for Serial in addition to the LCD. In general, it's best to avoid using pins 0 and 1.

You need to change the LCD wiring to use a different pin and update the code accordingly. For example, if you moved the LCD's RS pin connection from pin 1 on your Arduino to pin 13, you would update this line from:



LiquidCrystal lcd(1, 2, 4, 5, 6, 7);


to:

LiquidCrystal lcd(13, 2, 4, 5, 6, 7);


After that, your LCD should work correctly.