user67963: I am using the Arduino's Adafruit Finger Sensor library, and it has an example to enroll a fingerprint. I want it to enroll one print and exit/break out of the loop because it currently enrolls a user, then goes back to asking for a fingerprint.
Here is the code:
#include <Adafruit_Fingerprint.h>
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);
uint8_t id;
void setup()  
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;
  
  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println("Ready to enroll a fingerprint!");
  Serial.println("Please type in the ID # (from 1 to 127) you want to save this finger as...");
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print("Enrolling ID #");
  Serial.println(id);
  
  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print("Waiting for valid finger to enroll as #"); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  Serial.println("Remove finger");
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print("ID "); Serial.println(id);
  p = -1;
  Serial.println("Place same finger again");
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image taken");
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(".");
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println("Imaging error");
      break;
    default:
      Serial.println("Unknown error");
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println("Image converted");
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println("Image too messy");
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println("Communication error");
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println("Could not find fingerprint features");
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println("Could not find fingerprint features");
      return p;
    default:
      Serial.println("Unknown error");
      return p;
  }
  
  // OK converted!
  Serial.print("Creating model for #");  Serial.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println("Prints matched!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println("Fingerprints did not match");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
  
  Serial.print("ID "); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println("Stored!");
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println("Communication error");
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println("Could not store in that location");
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println("Error writing to flash");
    return p;
  } else {
    Serial.println("Unknown error");
    return p;
  }   
}

Output is that after storing the fingerprint, it requests for finger to enroll, but I want it to exit after storing. Is this possible?

user42015: Your getFingerprintEnroll() function is missing a return statement. Inside the if (p == FINGERPRINT_OK) statement, you need to insert
return 0;

after the Serial print. Only when returning zero, you will exit the while loop inside the loop() function.

67963: <p>I am using the Arduino's Adafruit Finger Sensor library, and it has an example to enroll a fingerprint. I want it to enroll one print and exit/break out of the loop because it currently enrolls a user, then goes back to asking for a fingerprint.
Here is the code:</p>
<pre><code>#include &lt;Adafruit_Fingerprint.h&gt;
SoftwareSerial mySerial(2, 3);
Adafruit_Fingerprint finger = Adafruit_Fingerprint(&amp;mySerial);
uint8_t id;
void setup()  
{
  Serial.begin(9600);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println(&quot;\n\nAdafruit Fingerprint sensor enrollment&quot;);

  // set the data rate for the sensor serial port
  finger.begin(57600);
  
  if (finger.verifyPassword()) {
    Serial.println(&quot;Found fingerprint sensor!&quot;);
  } else {
    Serial.println(&quot;Did not find fingerprint sensor :(&quot;);
    while (1) { delay(1); }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;
  
  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

void loop()                     // run over and over again
{
  Serial.println(&quot;Ready to enroll a fingerprint!&quot;);
  Serial.println(&quot;Please type in the ID # (from 1 to 127) you want to save this finger as...&quot;);
  id = readnumber();
  if (id == 0) {// ID #0 not allowed, try again!
     return;
  }
  Serial.print(&quot;Enrolling ID #&quot;);
  Serial.println(id);
  
  while (!  getFingerprintEnroll() );
}

uint8_t getFingerprintEnroll() {

  int p = -1;
  Serial.print(&quot;Waiting for valid finger to enroll as #&quot;); Serial.println(id);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println(&quot;Image taken&quot;);
      break;
    case FINGERPRINT_NOFINGER:
      Serial.println(&quot;.&quot;);
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println(&quot;Communication error&quot;);
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println(&quot;Imaging error&quot;);
      break;
    default:
      Serial.println(&quot;Unknown error&quot;);
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(1);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println(&quot;Image converted&quot;);
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println(&quot;Image too messy&quot;);
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println(&quot;Communication error&quot;);
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println(&quot;Could not find fingerprint features&quot;);
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println(&quot;Could not find fingerprint features&quot;);
      return p;
    default:
      Serial.println(&quot;Unknown error&quot;);
      return p;
  }
  
  Serial.println(&quot;Remove finger&quot;);
  delay(2000);
  p = 0;
  while (p != FINGERPRINT_NOFINGER) {
    p = finger.getImage();
  }
  Serial.print(&quot;ID &quot;); Serial.println(id);
  p = -1;
  Serial.println(&quot;Place same finger again&quot;);
  while (p != FINGERPRINT_OK) {
    p = finger.getImage();
    switch (p) {
    case FINGERPRINT_OK:
      Serial.println(&quot;Image taken&quot;);
      break;
    case FINGERPRINT_NOFINGER:
      Serial.print(&quot;.&quot;);
      break;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println(&quot;Communication error&quot;);
      break;
    case FINGERPRINT_IMAGEFAIL:
      Serial.println(&quot;Imaging error&quot;);
      break;
    default:
      Serial.println(&quot;Unknown error&quot;);
      break;
    }
  }

  // OK success!

  p = finger.image2Tz(2);
  switch (p) {
    case FINGERPRINT_OK:
      Serial.println(&quot;Image converted&quot;);
      break;
    case FINGERPRINT_IMAGEMESS:
      Serial.println(&quot;Image too messy&quot;);
      return p;
    case FINGERPRINT_PACKETRECIEVEERR:
      Serial.println(&quot;Communication error&quot;);
      return p;
    case FINGERPRINT_FEATUREFAIL:
      Serial.println(&quot;Could not find fingerprint features&quot;);
      return p;
    case FINGERPRINT_INVALIDIMAGE:
      Serial.println(&quot;Could not find fingerprint features&quot;);
      return p;
    default:
      Serial.println(&quot;Unknown error&quot;);
      return p;
  }
  
  // OK converted!
  Serial.print(&quot;Creating model for #&quot;);  Serial.println(id);
  
  p = finger.createModel();
  if (p == FINGERPRINT_OK) {
    Serial.println(&quot;Prints matched!&quot;);
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println(&quot;Communication error&quot;);
    return p;
  } else if (p == FINGERPRINT_ENROLLMISMATCH) {
    Serial.println(&quot;Fingerprints did not match&quot;);
    return p;
  } else {
    Serial.println(&quot;Unknown error&quot;);
    return p;
  }   
  
  Serial.print(&quot;ID &quot;); Serial.println(id);
  p = finger.storeModel(id);
  if (p == FINGERPRINT_OK) {
    Serial.println(&quot;Stored!&quot;);
  } else if (p == FINGERPRINT_PACKETRECIEVEERR) {
    Serial.println(&quot;Communication error&quot;);
    return p;
  } else if (p == FINGERPRINT_BADLOCATION) {
    Serial.println(&quot;Could not store in that location&quot;);
    return p;
  } else if (p == FINGERPRINT_FLASHERR) {
    Serial.println(&quot;Error writing to flash&quot;);
    return p;
  } else {
    Serial.println(&quot;Unknown error&quot;);
    return p;
  }   
}
</code></pre>
<p>Output is that after storing the fingerprint, it requests for finger to enroll, but I want it to exit after storing. Is this possible?</p>
 42015: <p>Your <code>getFingerprintEnroll()</code> function is missing a return statement. Inside the <code>if (p == FINGERPRINT_OK)</code> statement, you need to insert</p>
<pre><code>return 0;
</code></pre>
<p>after the Serial print. Only when returning zero, you will exit the while loop inside the <code>loop()</code> function.</p>
