Open / Close {}[]

Hello, I think I see a “syntax check” bug here:

#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <SPI.h>
#include <SD.h>
#include <Wire.h>

int Dis = 1;
int Mode = 1;

void setup() {
  // put your setup code here, to run once:
  Mode = 4;
}

void loop() {

// ************************************next line error compilation
  if (Dis == 1)     Heading();

  if (Mode == 4)  {
    Process4();
  }

}

void Process4(void) {

  int MsgLength = 0;
  int Sum = 0;
  byte checksum1 = 0;
  byte checksum2 = 0;


  delay(500);
  File dataFile4 = SD.open(FileOpen[4], FILE_READ);
  FileStart = dataFile4.position();
  MsgLength = 75;
 
  milold40 = millis() - Period;
  milold100 = millis() - Period100;
  delay(2);

  while (Mode == 4)  {
    if  (millis() > (milold100 + Period100)) {
      for (x = 1; x <= MsgLength; x++) {
        inbyte = dataFile4.read();
        InMessage[x] = inbyte;
      }

      milold100 = millis();
      if ((dataFile4.position() + MsgLength) > dataFile4.size()) {
        dataFile4.seek(FileStart);
      }
      FreshData = 1;
    }

    if (FreshData == 1) {
      FreshData = 0;
      for (x = 1; x < 76; x++) WorkMessage[x] = InMessage[x];
    }

   
    XPseconds = ((WorkMessage[10] * 655.36) + (WorkMessage[11] * 2.56) + (WorkMessage[12] * 0.01));

    if (XPseconds > 32767.999) OutMessage[17] = 1;
    else OutMessage[17] = 0;
    
    // *****************************************************next line
    
    OutMessage[18] = byte(int(XPseconds) - (OutMessage{17] * 32768) / 256) - byte(int(XPseconds) % 256);
    
    // ****************************************************above line
    
    OutMessage[19] = byte(int(XPseconds) % 256);

    
    for (MsgCount = 1; MsgCount < 33; MsgCount ++)
    {
      Sum = 0;
      if (MsgCount > 32) MsgCount = 1;
      if (MsgCount < 9) OutMessage[15] = MsgCount; //BlockNo
      else OutMessage[15] = 0;
      for (x = 24; x < 32; x++) {
        OutMessage[x] = 0;
      }
      if (MsgCount == 1)
      {
      }
      else if (MsgCount == 2)
      {
      }
      else {
      }
      for (x = 0; x < 31; x++) {
      }
      checksum2 = Sum - 1;
      checksum1 = 255 - checksum2;
      OutMessage[32] = checksum1;
      OutMessage[33] = checksum2;
      if (Dis == 1)
        Heading();
      while (millis() < (milold40 + Period)) {
        delay(0); //wait 40ms timemark
      }
      for (x = 1; x < 34; x++) {
       
      }
    Serial.println(millis() - milold40);
    milold40 = millis();
    Serial.println();
    }
    ReadSerial();
    }
    dataFile4.close();
    delay(500);
    }

    void Heading(void) {
    float Heading = 0.0;
    float Roll = 0.0;
    float Pitch = 0.0;
    }

I have cut some parts of the code because the subject is syntax and not Logic
ok.
Above code is what I get from Auto Format. Since I was working in the middle of function “process4” and function was working previously, i did not look at the bottom.
Verify : In First line within “loop” (there is a mark in code) :
Error message “Heading was not declared in this scope”

The real problem is within “process4” about 35 lines from beginning (there is a markin code).
OutMessage{17] : index is in {] and not .
But, compiler sees a closing “]” without having “hanged” open “[”. So why goes on and stops only when (finally) cannot close the "while (Mode == 4) " loop?

I strongly believe it should stop on specific statement.

(deleted)

Can somebody be more specific pls?

demkat1:
So why goes on and stops only when (finally) cannot close the "while (Mode == 4) " loop?

The compiler keeps going, trying to make sense of your code, until it gets to something it can’t swallow.

…R