expected 'while' before '(' token

For some reason it doesn’t think I closed out my loop… I have a { and a }.

What is going on?

Funny thing is that if I put a “while if”, nonsensical as it is, it doesn’t error out.

do while ((response == “”) && (clients.available())) {
response = clients.readStringUntil(’\n’);
}
if (response == “235”) {
DEBUG_AM(“235 LOGGED IN OK”);
}

Here is the function:

bool Gsender_Send() {
  DEBUG_AM("Connecting to :");
  DEBUG_AM(smtp_server);
  DEBUG_AM(smtp_port);
  clients.connect(smtp_server, smtp_port);
  if (clients.connected() == false) {
    _error = "Not connected";
    DEBUG_AM(_error);
  }
  String response = "";
  do while (response == "") {
      while (clients.available()) {
        response = clients.readStringUntil('\n');
      }
    }
  if (response == "220") {
    DEBUG_AM("220 OK");
  }

  DEBUG_AM("HELO friend:");
  clients.println("HELO friend");

  do while (response == "") {
      while (clients.available()) {
        response = clients.readStringUntil('\n');
      }
    }
  if (response == "250") {
    DEBUG_AM("250 HELO OK");
  }

  DEBUG_AM("AUTH LOGIN:");
  clients.println("AUTH LOGIN");

  do while (response == "") {
      while (clients.available()) {
        response = clients.readStringUntil('\n');
      }
    }
  if (response == "334") {
    DEBUG_AM("334 AUTH OK");
  }


  DEBUG_AM("smtpUserID:");
  DEBUG_AM(smtpUserID);

  clients.println(encode64(csmtpUserID));
  do while (response == "") {
      while (clients.available()) {
        response = clients.readStringUntil('\n');
      }
    }
  if (response == "334") {
    DEBUG_AM("334 USERID OK");
  }

  DEBUG_AM("smtp_pass:");
  DEBUG_AM(smtp_pass);

  clients.println(encode64(csmtp_pass));

  do while ((response == "") && (clients.available())) {
      response = clients.readStringUntil('\n');
    }
  if (response == "235") {
    DEBUG_AM("235 LOGGED IN OK");
  }



  String mailFrom = "MAIL FROM: <" + String(smtpFrom) + '>';
  DEBUG_AM(smtpFrom);
  clients.println(smtpFrom);
  Gsender_AwaitSMTPResponse(clients, "250", smtpTimeOut);

  String rcpt = "RCPT TO: <" + smtpTo + '>';
  DEBUG_AM(smtpTo);
  clients.println(smtpTo);
  Gsender_AwaitSMTPResponse(clients, "250", smtpTimeOut);

  DEBUG_AM("DATA:");
  clients.println("DATA");
  if (!Gsender_AwaitSMTPResponse(clients, "354", smtpTimeOut)) {
    _error = "SMTP DATA error";
    return false;
  }

  clients.println("From: <" + smtpFrom + '>');
  clients.println("To: <" + smtpTo + '>');

  clients.print("Subject: ");
  clients.println(subject);
  clients.println("Mime-Version: 1.0");
  clients.println("Content-Type: text/html; charset=\"UTF-8\"");
  clients.println("Content-Transfer-Encoding: 7bit");
  clients.println();
  clients.println(body);
  clients.println(".");
  if (!Gsender_AwaitSMTPResponse(clients, "250", smtpTimeOut)) {
    _error = "Sending message error";
    return false;
  }
  clients.println("QUIT");
  if (!Gsender_AwaitSMTPResponse(clients, "221", smtpTimeOut)) {
    _error = "SMTP QUIT error";
    return false;
  }
  return true;
}

There is no "do while" as you have implemented.

There is

do
{
  ...
  ...
} while(someCondition == true);

And in your case you can use as well

while(someCondition == true)
{
  ...
  ...
}

My advice would be to make all lines like this:

if (!Gsender_AwaitSMTPResponse(clients, "354", smtpTimeOut)) {

…rather look like this:

if (!Gsender_AwaitSMTPResponse(clients, "354", smtpTimeOut)) 
{

… with each { on its own line. Then do a control-t and let the ide sort out the indenting and it’s easier to see the { } pairing and mis-matches.

If you put your mouse by any { or } it will highlight its buddy } or { in a small box.

A look at the do while reference should answer your question about the (syntax) error.

Thanks, I have memory problems and I forgot the loop worked that way.