Loop untill sms sent

Hello guys,

in resume im working with a project that reads analog inputs and after they reach some value the enter in this function readLocation() below:

void readLocation(){

   if(isFirst) {
    isFirst = 0;
    return;
  }

  memset(message,0,sizeof(message));


  
  bool newData = false;
  unsigned long chars = 0;
  unsigned short sentences, failed;

  // For one second we parse GPS data and report some key values
  for (unsigned long start = millis(); millis() - start < 1000;)
  {
    while (Serial1.available())
    {
      int c = Serial1.read();
//      Serial.print((char)c); // if you uncomment this you will see the raw data from the GPS
      ++chars;
      if (gps.encode(c)) // Did a new valid sentence come in?
        newData = true;
    }
  }
  
  if (newData)
  {
    // we have a location fix so output the lat / long and time to acquire
    if(secondsToFirstLocation == 0){
      secondsToFirstLocation = (millis() - startMillis) / 1000;
      Serial.print("Acquired in:");
      Serial.print(secondsToFirstLocation);
      Serial.println("s");
    }
    
    unsigned long age;
    gps.f_get_position(&latitude, &longitude, &age);
    
    latitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : latitude;
    longitude == TinyGPS::GPS_INVALID_F_ANGLE ? 0.0 : longitude;

  
    dtostrf(latitude, 10, 6, lats);
    strcat(message, lats);
    strcat(message,"#");
    
    dtostrf(longitude, 10, 6, lons); 
    strcat(message, lons);
    strcat(message,"#");   

    dtostrf (res, 8, 6, forca);
    strcat(message, forca);
    strcat(message,"#");
    strcat (message, "ASO-5577#BWM");
   
      
         
    
   fona.sendSMS(sendto, message); 
   
     
  if (chars == 0){
    // if you haven't got any chars then likely a wiring issue
    Serial.println("Check wiring");
  }
  else if(secondsToFirstLocation == 0){
    // still working
  }

  }

  
}

I need a help with 2 things:

  1. How do i create a loop inside this funcion till the sms was sent.
  2. How do i create a loop inside this sms loop, that will stay till latitude and longitude are not null.

What tells you that an SMS has been sent?

I would break your code into smaller functions - each with just one purpose. That way it will be easier to manage their interaction. See Planning and Implementing a Program

Using time in the hope that you receive enough characters is unreliable. Have a look at the second example in Serial Input Basics

...R

  for (unsigned long start = millis(); millis() - start < 1000;)

Quit abusing the for statement that way. That should obviously be a while loop.