Problem with a simple program (reading push button presseS)

Im having an issue with a simple program. My program is intended to have a pushbutton that drives an output. This push button does 4 things.

press (and release) 1: (command)
press (and release) 2:(command 2)
press (and release) 3:(command 3)
press (and release) 4:(reset/off)

the problem i am having is in this current state i press the button and it goes into the while loop, but it completely ignores the nested "if" statement and increments the i variable regardless of the state of the push button and will stay in the while loop "x" number of times i have the while(i<=x) set for.

const int led = 10;     //led pin 10
int pb = 7;                 //push button pin 7
int i;


void setup()
{
  pinMode(led,OUTPUT);
  pinMode(pb,INPUT);
}

void loop()
{
  
  pb=digitalRead(7);                       //pb = pushbutton state high or low
  i=1;                                            // counting variable
  
  if(pb==HIGH)                                //if pb is pressed
  {
   while(i<=4)                                  
   {
    delay(500); 
    digitalWrite(led,HIGH);
    delay(500);
    digitalWrite(led,LOW);
   
    if(pb==HIGH)
    {
    i++;
    }
   }
  }
}
int pb = 7;                 //push button pin 7
  pb=digitalRead(7);                       //pb = pushbutton state high or low

So, is pb a pin number or a state? Get your story straight.

How IS your switch wired? Using the internal pullup resistor makes wiring the switch so much easier. One leg to the digital pint; the other leg to ground.

Just from looking, not from running;

Push and release means checking that the button has been released, which you don't do.

It would probably be good if you get rid of that first delay, you won't need it if you check release.

Also, do you know what debounce means?

PaulS:

int pb = 7;                 //push button pin 7

pb=digitalRead(7);                       //pb = pushbutton state high or low



So, is pb a pin number or a state? Get your story straight.

How IS your switch wired? Using the internal pullup resistor makes wiring the switch so much easier. One leg to the digital pint; the other leg to ground.

My switch is being run into a debounce IC
pb is the variable that i want my digitalRead(7) stored in, so i guess i dont need that int pb 7?

To the other guy, it doesnt really matter if it is responding to the push, or the push and release, i was just clarifying that it is being released.

and it goes into the while loop, but it completely ignores the nested "if" statement and increments the i variable regardless of the state of the push button and will stay in the while loop "x" number of times i have the while(i<=x) set for.

You never read the state of the switch after the while loop starts. Since pb had to be HIGH for the while loop to start, it is HIGH in the while loop, too.