Help with code error 'buttonState does not name type'

I'm new to Arduino and writing code. So I down loaded DHT22 fan control program and adapted it for my own control purposes to provide separate humidity and temperatures values as set and provide high stae outputs on the designated pins. After sorting out errors and mistakes my adapted code compiles with no errors and performs the tasks I need.
I then took it a stage further wanting to use pin 0 as an input with a push button switch, when the switch is pressed it turns pin 6 to HIGH and back to LOW on release.
Using the Button.sketch example from the Arduino Examples I have attempted to merge it into my Sketch as submitted. An error code ' Button state does not name a type' error shows up. I've gone through my listing but can't see any obvious mistakes, can any one help me please, I'm a 72 years old newbie.
Great full for any help.

#include "DHT.h"

#define DHTPIN 2     // pin 2 sensor is connected to
#define DHTTYPE DHT22   // DHT 22  (AM2302)
#define fan 4
#define vent 5
#define door 6
// constants won't change. They're used here to set pin numbers:
const int buttonPin = 0;     // the number of the pushbutton pin
const int ledPin = 6;      // the number of the LED / output pin    

// variables will change
int buttonState = 0;   // variable  for reading the push button status
int maxTemp2 = 28;
int maxTemp = 24;       // 18
int minTemp = 20;       //15
int maxHum  = 60;
int minHum  = 55; 

void setup() {
  pinMode(fan, OUTPUT);
  pinMode(vent, OUTPUT);
  pinMode(door, OUTPUT);
  pinMode(ledPin, OUTPUT);
  pinMode(buttonPin, INPUT);

void loop() {

     buttonState = digitalRead(buttonPin);
     if (buttonState == HIGH) {
     digitalWrite(ledPin, HIGH);
     } else {
     digitalWrite(ledPin, LOW);
  // Wait a few seconds between measurements.

  // Reading temperature or humidity takes about 250 milliseconds!
  // Sensor readings may also be up to 2 seconds 'old' (its a very slow sensor)
  float h = dht.readHumidity();
  // Read temperature as Celsius
  float t = dht.readTemperature();
  // Check if any reads failed and exit early (to try again).
  if (isnan(h) || isnan(t)) {
    Serial.println("Failed to read from DHT sensor!");

 //==================================== read the state of the pushbutton value:============
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed. If it is, the buttonState is HIGH:
  if (buttonState == HIGH) {    // check high low input state?
   digitalWrite(door, HIGH);
  } else {
   digitalWrite(door, LOW);
  // checking humidity sensors to control fan if high fan on =================================
   if(h > maxHum) {
    digitalWrite(vent, HIGH);
    digitalWrite(fan, HIGH);
  } else
    if(h < minHum) {
     digitalWrite(fan, LOW); 
  // ==========================================================================================
  //=================================== door temp added = temp2 ================================
  if(t > maxTemp2) {
  //  digitalWrite(fan, HIGH);
     digitalWrite(door, HIGH);
  // New line entered to turn off vent and Fan off   
  } else     
   if(t < minTemp) {                                                       
    digitalWrite(door, LOW); 
   // ============================================================================================
  Serial.print("Humidity: "); 
  Serial.print(" %\t");
  Serial.print("Temperature: "); 
  Serial.println(" *C ");


An error code ' Button state does not name a type' error shows up

Is that the exact error message, or just something you misremembered?

 //==================================== read the state of the pushbutton value:============
  buttonState = digitalRead(buttonPin);

This code is not in a function.