How to use NO_KEY ?

Hi I’m studying some keypad functions and I encounter this handy condition but I don’t know how it works.
I did a simple test in where word will display if you use NO_KEY and then the lcd will clear and display new set of string.

Here’s my code

#include <Keypad.h>
#include <Wire.h>
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3,POSITIVE); 
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char customkey;
char hexaKeys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};

byte rowPins[ROWS] = {8, 7, 6, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {9, 10, 11, 12}; //connect to the column pinouts of the keypad


//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);



void setup (){
   Serial.begin(9600);
    lcd.begin(16,2);
}

void loop() 
{
customkey = customKeypad.getKey();



while(customkey == NO_KEY )
{ customkey = customKeypad.getKey();
  lcd.print ("HELLLO");} 

if (customkey != NO_KEY)
{
  switch(customkey)
  {
    case '1':
    lcd.clear();
    lcd.setCursor(9,0);
    lcd.print("WELCOME");
    break;
  }
  }
}

My main problem is the word HELLO keeps on displaying even if the condition about NO_KEY is terminated after pressing a KEY

Any help is appreciated,

THANK YOU!

Don't forget that the loop() function repeats many times per second so the while loop will be entered many times per second and while a key is not pressed "HELLO" will be printed.

Under what circumstances do you want "HELLO" to be printed ?

Generally it's a bad idea to put your sketch in a loop waiting for a key press. Humans are very slow and your sketch can be doing useful stuff other than waiting for a human. You also don't need to check for NO_KEY before you decise what to do with the key value. Just pass every value on to the switch/case statement. If you want something special done when no key was pressed, you can make a 'case NO_KEY:'.

void setup () {
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print ("HELLLO");  // Dispay "HELLO" until the '1' key is pressed.
}

void loop() 
{
  customkey = customKeypad.getKey();

  switch(customkey) {
  case '1':
    lcd.clear();
    lcd.setCursor(9,0);
    lcd.print("WELCOME");
    break;
  }
}