Still not in code tags (# button when posting your message)
Highlight your code then click the # button above the edit window.
As to your code, I think that you have made it more complicated than it needs to be.
I would do it something like this
int buttonPin = 2;
int yellowLed = 3;
int redLed = 4;
int greenLed = 5;
int currentLed = 2;
void setup() {
pinMode(buttonPin, INPUT); // set the switch pin to be an input
pinMode(yellowLed, OUTPUT); // set the yellow LED pin to be an output
pinMode(redLed, OUTPUT); // set the red LED pin to be an output
pinMode(greenLed, OUTPUT); //set green pin as output
}
void loop()
{
if (digitalRead(buttonPin) == LOW)
{
switch (currentLed)
{
case 2: // no LEDs on
digitalWrite(yellowLed, LOW); // turn on the yellow LED
currentLed++;
break;
case 3: //yellow LED is on
digitalWrite(redLed, LOW); // turn on the red LED
currentLed++;
break;
case 4: //red & yellow LEDs are on
digitalWrite(greenLed, LOW); // turn on the green LED
currentLed++;
break;
default: //all 3 LEDs are on
digitalWrite(yellowLed, HIGH); // turn off the yellow LED
digitalWrite(redLed, HIGH); // turn off the red LED
digitalWrite(greenLed, HIGH); // turn off the green LED
currentLed = 2; //reset the counter
}
}
}
NOTE - I have not tested this so it could still be full of holes, but you will see the principle involved
I have assumed that making the LED pins LOW as in your code turns them on, but that depends on how you have them wired
I have also assigned names to the pins used to make the code easier to read.
IMPORTANT NOTE - there is nothing in the code at the moment to debounce the button, so pressing it once may cycle through several states instead of moving on to the next one.