Simple do loop problem

I have a fairly complex program which is running OK, and in which I have several "do loops."
However I have run into a problem in using one in a particular place.

I wish to have certain functions performed at power turn-on.
Therefore I have included a switch, which will ground Pin 5 if pressed at turn-on, and the following code just after setup{

delay(50);
pinMode( 5, INPUT);
H = digitalRead(5);

/////////// below doesn't work /////////////////
while ( H == 0 ) {
delay(50); // just wait until switch is released
}
// Nor does this:
do{
delay(50);
} while ( H == 0 );
/////////////////////////////////////////////////

This hardware pin is shared with the LCD Display "enable" function, and after the above code I initialize the display and all works well from there on. (The display is inoperable during the initial turn-on, as it is initialized only after the initial switch test. )

A test on H later (after display initialization) shows that H follows the switch on/off correctly. However, I would like to have the program wait until the switch is released before proceeding, and I haven't figured out how to do that.

I don't understand why a simple "while" statement won't work. Any suggestions?

You must read the pin in the loop, otherwise the state of H never change.

For instance, in each loop, replace H with

digitalRead (5);

However, I would like to have the program wait until the switch is released before proceeding, and I haven't figured out how to do that.

Look at the state change detection example. It shows how to sense the transitions (low to high or high to low).

Thanks a big heap!

I thought it must be something simple, but kept on thinking that being the first lines of the program had something to do with the problem.
Sometimes we get blind-sided by the obvious!

Thanks again -
Matt