How to code for dry contact open/close not in loop

if (digitalRead(Switch) == HIGH) {
    Serial.println("Open");
    delay(10);
    while( digitalRead(Switch) == HIGH) { } // do nothing until low
  }
  else {
        Serial.println("Close");
       while( digitalRead(Switch) == LOW) { } // do nothing until high
  }