Verification problem using For and If statements.

Hello, just wondering if someone can help me out with a program problem I'm having. Let me just say I'm very new to Arduino programming, so I may be making some silly mistake. If so I'll apologise up front.
The program is meant to monitor sensors attached to 4 doors and when all doors are closed an output is activated to operate a valve. Looking at possible ways of doing it I decided to try using a For loop arrangement to specify input pin numbers, Then another to monitor if the inputs went high and activate the output. Trouble is the code won't verify, and I can't see what the problem is.
Here's the code:

  /* Program to monitor the state of 4 doors to see if they are open or closed
   each door fitted with a switch to send signal to Arduino (pins 2, 3, 4, 5)
   if all doors closed an output at pin 8 should go high to activate a solenoid valve
  */

  int solValve = 8;  //sets pin 8
 
  
void setup() {
  
   pinMode (solValve, OUTPUT); // define mode for pin 8 as output
  
   for (int doorSense = 2; doorSense <5; doorSense ++)  // assigns INPUT pin numbers from 4 door-mounted sensors
   {
     pinMode (doorSense, INPUT);  //define mode for pins 2 to 5 as inputs
   }
   
}

void loop() {
  
    // scan the status i.e. on/off of 4 door sensors to see when all doors are closed
    
   for (int doorSense = 2; doorSense <5; doorSense ++)
   {
     digitalRead (doorSense);
   }
       if (doorSense == HIGH)            //looking for HIGH inputs from all 4 doors
       {
         digitalWrite (solValve, HIGH);  //if all doors closed then output at 
                                         //pin 8 goes HIGH to activate a solenoid valve
       }
}

And here is the error message:

Arduino: 1.6.1 (Windows XP), Board: "Arduino Uno"

Door_Switch_sketch_02.ino: In function 'void loop()':

Door_Switch_sketch_02.ino:29:12: error: name lookup of 'doorSense' changed for ISO 'for' scoping [-fpermissive]

Door_Switch_sketch_02.ino:29:12: note: (if you use '-fpermissive' G++ will accept your code)

Error compiling.

Many thanks in advance for any help.
Phil.

   for (int doorSense = 2; doorSense <5; doorSense ++)
   {
     digitalRead (doorSense);
   }
       if (doorSense == HIGH)            //looking for HIGH inputs from all 4 doors

Once the for loop has completed doorSense, which has been declared as part if the for loop no longer has any meaning. Have you got the closing brace for the for loop in the wrong place ?

Another observation. The for loop runs from 2 to 4 and does not, therefore, have 4 values.

Your program had several problems.

if (doorSense == HIGH)

The code above compare the pin number with HIGH not the state of the pin.

Since you need all the doors to be closed before activating a solenoid, it's easy to check for any one door being open. If a closed door will result in a high pin state, then the following should detect an open door.

   if (digitalRead (doorSense) != HIGH)            //assume closed doors result in high reading, looking for an open door
    {
      allDoorsClosedFlag = 0; // any one door will change flag
    }

The code below compiles and I think it should do what you want.

/* Program to monitor the state of 4 doors to see if they are open or closed
 each door fitted with a switch to send signal to Arduino (pins 2, 3, 4, 5)
 if all doors closed an output at pin 8 should go high to activate a solenoid valve
*/

int solValve = 8;  //sets pin 8


void setup()
{
  pinMode (solValve, OUTPUT); // define mode for pin 8 as output

  for (int doorSense = 2; doorSense <= 5; doorSense++) // assigns INPUT pin numbers from 4 door-mounted sensors
  {
    pinMode (doorSense, INPUT);  //define mode for pins 2 to 5 as inputs
  }
}

void loop()
{
  // scan the status i.e. on/off of 4 door sensors to see when all doors are closed
  boolean allDoorsClosedFlag = 1; // start assuming all the doors are closed
  for (int doorSense = 2; doorSense <= 5; doorSense++)
  {
    if (digitalRead (doorSense) != HIGH)            //assume closed doors result in high reading, looking for an open door
    {
      allDoorsClosedFlag = 0; // any one door will change flag
    }
  }
  if (allDoorsClosedFlag)
  {
    digitalWrite (solValve, HIGH);  //if all doors closed then output at
    //pin 8 goes HIGH to activate a solenoid valve
  }
}

UKHeliBob:
Once the for loop has completed doorSense, which has been declared as part if the for loop no longer has any meaning. Have you got the closing brace for the for loop in the wrong place ?

I'm guessing this is why the original code didn't compile.

UKHeliBob:
Another observation. The for loop runs from 2 to 4 and does not, therefore, have 4 values.

Agreed. The code I posted uses "<=" instead of "<".