Problem with compiling

Hi

i’m working on a program and when i upload it the program says this: expected unqualified-id before ‘if’.
Is there someone who can helf me, don’t find my mistake.

here is my program:

      /***************************************************
  Must use ESP8266 Arduino from:
    https://github.com/esp8266/Arduino

  Works great with Adafruit's Huzzah ESP board:
  ----> https://www.adafruit.com/product/2471
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!

  Written by Richard Albritton, based on original code by Tony DiCola 
  for Adafruit Industries. Adafruit IO example additions by Todd Treece.
  MIT license, all text above must be included in any redistribution
 ****************************************************/
#include <ESP8266WiFi.h>
#include "Adafruit_MQTT.h"
#include "Adafruit_MQTT_Client.h"

/****************************** Pins ******************************************/

#define Buttons       A0  // analog 0

/************************* WiFi Access Point *********************************/

#define ssid          "ProSuite_2.4GHz"
#define password      "ProSuite_24"

/************************* Adafruit.io Setup *********************************/

#define AIO_SERVER      "io.adafruit.com"
#define AIO_SERVERPORT  1883
#define AIO_USERNAME    "Stagiairdja"
#define AIO_KEY         "Stage@DJA"

/************ Global State (you don't need to change this!) ******************/

// Create an ESP8266 WiFiClient class to connect to the MQTT server.
WiFiClient client;

// Store the MQTT server, client ID, username, and password in flash memory.
// This is required for using the Adafruit MQTT library.
const char MQTT_SERVER[] PROGMEM    = AIO_SERVER;
// Set a unique MQTT client ID using the AIO key + the date and time the sketch
// was compiled (so this should be unique across multiple devices for a user,
// alternatively you can manually set this to a GUID or other random value).
const char MQTT_CLIENTID[] PROGMEM  = __TIME__ AIO_USERNAME;
const char MQTT_USERNAME[] PROGMEM  = AIO_USERNAME;
const char MQTT_PASSWORD[] PROGMEM  = AIO_KEY;

// Setup the MQTT client class by passing in the WiFi client and MQTT server and login details.
Adafruit_MQTT_Client mqtt(&client, MQTT_SERVER, AIO_SERVERPORT, MQTT_CLIENTID, MQTT_USERNAME, MQTT_PASSWORD);/****************************** Feeds ***************************************/

// Setup a feed called 'remote-buttons' for publishing changes.
// Notice MQTT paths for AIO follow the form: <username>/feeds/<feedname>
const char RemoteButtons_FEED[] PROGMEM = AIO_USERNAME "/feeds/remote-buttons";
Adafruit_MQTT_Publish RemoteButtons = Adafruit_MQTT_Publish(&mqtt, RemoteButtons_FEED);

/*************************** Sketch Code ************************************/

// remote-buttons state
int ButtonRead = 0;
int current = 0;
int previous = -1;
int Button;

void setup() {

  pinMode(2, OUTPUT);
  pinMode(13, INPUT);
  
  Serial.begin(115200);

  Serial.println(F("Adafruit IO Example"));

  // Connect to WiFi access point.
  Serial.println();
  delay(10);
  Serial.print(F("Connecting to "));
  Serial.println(ssid);

  WiFi.begin(ssid, password);
  
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(F("."));
  }
  
  Serial.println(F("."));
  Serial.println(F("WiFi connected"));
  Serial.println(F("IP address: "));
  Serial.println(WiFi.localIP());

  // connect to adafruit io
  connect();

}

void loop() {

  // ping adafruit io a few times to make sure we remain connected
  if(! mqtt.ping(3)) {
    // reconnect to adafruit io
    if(! mqtt.connected())
      connect();
    }
    Serial.print("\n");
    Serial.print(digitalRead(Buttons));
    ButtonRead = digitalRead(Buttons);
    delay(1);
    
    // grab the current state of the remote-buttons
    
    Button = digitalRead(13);

    if (Button == HIGH && previous == LOW){
      if(current == HIGH)
      current = LOW;
      else
      current = HIGH;
    }
digitalWrite(2, current);
previous = Button;
}
  // return if the value hasn't changed
  if(current == last)
    return;

  int32_t value = current;

  // Now we can publish stuff!
  Serial.print(F("\nSending RemoteButtons value: "));
  Serial.print(value);
  Serial.print("... ");

if (! RemoteButtons.publish(value))
    Serial.println(F("Failed."));
  else
    Serial.println(F("Success!"));

  // save the RemoteButtons state
  last = current;

}

// connect to adafruit io via MQTT
void connect() {

  Serial.print(F("Connecting to Adafruit IO... "));

  int8_t ret;

  while ((ret = mqtt.connect()) != 0) {

    switch (ret) {
      case 1: Serial.println(F("Wrong protocol")); break;
      case 2: Serial.println(F("ID rejected")); break;
      case 3: Serial.println(F("Server unavail")); break;
      case 4: Serial.println(F("Bad user/pass")); break;
      case 5: Serial.println(F("Not authed")); break;
      case 6: Serial.println(F("Failed to subscribe")); break;
      default: Serial.println(F("Connection failed")); break;
    }

    if(ret >= 0)
      mqtt.disconnect();

    Serial.println(F("Retrying connection..."));
    delay(5000);

  }

  Serial.println(F("Adafruit IO Connected!"));

}

Moderator edit: And there’s your code WITH CODE TAGS
Also corrected thread title.

when i upload it the program says this: expected unqualified-id before 'if'.

That is NOT all that it says. It tells you the EXACT line that it has problems with. That IS important information.

You have obviously failed to read the stickies at the top of the forum. Read them NOW, and fix your post.

// return if the value hasn't changed
if (current == last)
  return;

This code and lots after it is outside of a function. Check carefully where the loop() function ends. Auto-formatting the code (Ctrl-T) shows up the problem. It would also have been helpful if you had put teh code in code tags.

read this before posting a programming question