Program for Garage door control

This program will close either Garage Door if left open more than 5 minutes or so.
But I have a question....
Snippet of confounding problem....I would never think this would work this way as it could be of value sometime but not in my circuit now even though it works well.
Any help would be appreciated.

with "switchpin2 HIGH" the "digitalWrite(relayPin6, HIGH);"
stops at the ; and won't continue with "digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 1" until "switchpin2=LOW". ....Then in the same block below with
((digitalRead (switchPin3) == LOW)) it will not execute the "digitalWrite(relayPin7, HIGH);" but will execute th "digitalWrite(A, LOW);digitalWrite(B, HIGH);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 2".
The reverse is also true.
can't seem to see the reason for this.

{
{while ((digitalRead (switchPin2) == HIGH))
digitalWrite(relayPin6, HIGH);digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 1
delay(1000);
digitalWrite(relayPin6, LOW);}
delay(500);
{while ((digitalRead (switchPin3) == HIGH))
digitalWrite(relayPin7, HIGH);digitalWrite(A, LOW);digitalWrite(B, HIGH);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 2
delay(1000);
digitalWrite(relayPin7, LOW);}
}

Below is the complete program.

/*June 1, 2015
Garage Door Closer for two doors, Stuarts
Closes the Doors if left open too long…Time set by program

The circuit:

  • Counter show relative time remaining....9 thru 0

  • Red LED attached from pin 11 to ground to Flash warning

  • 10K resistors attached to pin 2 to ground & Pin 3 to ground Pull down function
    *Switch hold circuit from 5V to pin 12
    & to Green LED on panel to Prevent auto close
    *100 Ohm resister from Green LED to ground to drop voltage on Green LED
    *10K resistor from Pin 12 to ground Pull down function.
    *Output 5v from Pin 6 to relay 1 coil to close door 1
    *Output 5v from Pin 7 to relay 2 coil to close door 2

  • Note: on most Arduinos there is already an LED on the board
    attached to pin 13.

*/
// constants won't change. They're used here to
// set pin numbers:
const int switchPin2 = 2; // the number of the Door 1 Switch
const int switchPin3 = 3; // the number of the Door 2 Switch
const int relayPin6 = 6; // the number of the Output pin to Relay for Door 1 Close circuit
const int relayPin7 = 7; // the number of the Output pin to Relay for Door 2 Close circuit

const int ledPin11 = 11; // the number of the Red Flashing LED
const int holdPin12 = 12; // the number of the Stop/Hold Circuit
const int A=0;//for bcd out
const int B=1;//for bcd out
const int C=4;//for bcd out
const int D=5;//for bcd out
// variables will change:
int switchState2 = 0; // variable for reading the Door Switch 1 status
int switchState3 = 0; // variable for reading the Door Switch 2 status
int holdState = 0; // variable for reading the (Switch for green light light on = (holdstate=1)) Door Switch hold status
//int e;
int i;
void setup() {
// next is for bcd out
pinMode(A, OUTPUT); //LSB
pinMode(B, OUTPUT);
pinMode(C, OUTPUT);
pinMode(D, OUTPUT); //MSB

// initialize the pin as an output:
pinMode(relayPin6, OUTPUT);
pinMode(relayPin7, OUTPUT);

pinMode(ledPin11, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(switchPin2, INPUT);
pinMode(switchPin3, INPUT);
pinMode(holdPin12, INPUT);//Disable auto door closer
} // above set all the perameters for the in out switch functions etc

// int count = 0; //the variable used to show the number

// below is the program
void loop()
{
// read the state of the pushbutton & hold pin value:
holdState = digitalRead(holdPin12);
switchState2 = digitalRead(switchPin2);
switchState3 = digitalRead(switchPin3);
// check if a door switch is activated.
// if it is, the switchState is HIGH:
if (((switchState2 == HIGH)||(switchState3 == HIGH))&(digitalRead (holdPin12) ==LOW))
{int i=0;

do
{i=(i+1);
if ((digitalRead (holdPin12) ==HIGH)||(digitalRead (switchPin2) ==LOW)&&(digitalRead (switchPin3) ==LOW))
break;
// turn LED COUNTER on =9
if (i == 1) //write 9
{digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, HIGH);}
if (i == 70) //write 8
{digitalWrite(A, LOW);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, HIGH);}
if (i == 105) //write 7
{digitalWrite(A, HIGH);digitalWrite(B, HIGH);digitalWrite(C, HIGH);digitalWrite(D, LOW);}
if (i == 140) //write 6
{digitalWrite(A, LOW);digitalWrite(B, HIGH);digitalWrite(C, HIGH);digitalWrite(D, LOW);}
if (i == 175) //write 5
{digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, HIGH);digitalWrite(D, LOW);}
if (i == 210) //write 4
{digitalWrite(A, LOW);digitalWrite(B, LOW);digitalWrite(C, HIGH);digitalWrite(D, LOW);}
if (i == 245) //write 3
{digitalWrite(A, HIGH);digitalWrite(B, HIGH);digitalWrite(C, LOW);digitalWrite(D, LOW);}
if (i == 280) //write 2
{digitalWrite(A, LOW);digitalWrite(B, HIGH);digitalWrite(C, LOW);digitalWrite(D, LOW);}
if (i == 315) //write 1
{digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, LOW);}
if (i == 350) //write 0
{digitalWrite(A, LOW);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, LOW);}
if (i<350)
{// for counter

digitalWrite(ledPin11, HIGH); // turn the red LED on (HIGH is the voltage level)
delay(500);// wait for a .5 second
digitalWrite(ledPin11, LOW); // turn the red LED off by making the voltage LOW
delay(500);} // wait for a .5 second
// Count Delay for total time
if (i > 350)// for counter end
{
digitalWrite(ledPin11, HIGH); // turn the red LED on (HIGH is the voltage level)
delay(100);// wait for a .1 second
digitalWrite(ledPin11, LOW); // turn the red LED off by making the voltage LOW
delay(100);}// wait for a .1 second

//TO CLOSE DOOR WITH A SHORT PULSE
if (i > 448)
{
{while ((digitalRead (switchPin2) == HIGH))
digitalWrite(relayPin6, HIGH);digitalWrite(A, HIGH);digitalWrite(B, LOW);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 1
delay(1000);
digitalWrite(relayPin6, LOW);}
delay(500);
{while ((digitalRead (switchPin3) == HIGH))
digitalWrite(relayPin7, HIGH);digitalWrite(A, LOW);digitalWrite(B, HIGH);digitalWrite(C, LOW);digitalWrite(D, LOW);//Door 2
delay(1000);
digitalWrite(relayPin7, LOW);}
}

}

while (i<450); // ie wait for 10 seconds if i = 10 10 Minutes if i=600

}
else
{// turn LED off:
digitalWrite(relayPin6, LOW);
digitalWrite(relayPin7, LOW);
digitalWrite(ledPin11, LOW);

//TURN OFF DISPLAY
digitalWrite(A, LOW);
digitalWrite(B, HIGH);
digitalWrite(C, LOW);
digitalWrite(D, HIGH);
}

}

  { while ((digitalRead (switchPin2) == HIGH))
            digitalWrite(relayPin6, HIGH); digitalWrite(A, HIGH); digitalWrite(B, LOW); digitalWrite(C, LOW); digitalWrite(D, LOW); //Door 1

This seems to be the code that you are referring to.

Let's format it a different way

{ while ((digitalRead (switchPin2) == HIGH))
            digitalWrite(relayPin6, HIGH); 
            digitalWrite(A, HIGH); 
            digitalWrite(B, LOW); 
            digitalWrite(C, LOW); 
            digitalWrite(D, LOW); //Door 1

Leaving aside the superfluous braces and brackets only the first command after the while will be executed if the condition is true and the others will be executed unconditionally.

Did you perhaps mean to write

while (digitalRead (switchPin2) == HIGH)
  {
            digitalWrite(relayPin6, HIGH); 
            digitalWrite(A, HIGH); 
            digitalWrite(B, LOW); 
            digitalWrite(C, LOW); 
            digitalWrite(D, LOW); //Door 1
  }

Now all of the commands in the braces will be executed when the condition is true.

Thanks UKHeliBob, It works as I intended but why does the " line up of code above for the counter" work as it should? I guess I messed up on the brackets someway. Anyway you are very kind to take the time to help me out. Many thanks.
Buddy81

Are you asking why your do{}while() loop works but your while() loop does not?

If so its because you used curly braces in your do-while, but didn't with the while() loop.

Even if you put all separate commands on a single line separated by semicolons, only the first will be in the loop without curly braces.

The braces enclose the statements to be executed when the while loop condition is true. Without the braces only the first code statement is executed when the while condition is true. In my experience it is better to always include the braces even when there is only one statement to be executed, put the braces each on their own line and use AutoFormat in the IDE to make the code structure more obvious.