searching data inside the text file

hi good day , smile emoticon we have a project that we need to search the data inside the text file and compare it to the card_id. The problem is, only the first line of the text was being match it will not go further to the next line.

inside the text file:

here's my code:

myFile ="test.txt");
if (myFile) {

// read from the file until there's nothing else in it:
while (myFile.available()) {
String line = myFile.readStringUntil('\n');

String type = get_value(line, '|', 0);
String Name = get_value(line, '|', 1);

if (type == card_id)
Serial.println(type + "|" + Name);

Serial.println(F("Welcome, You shall pass"));
granted(300); // Open the door lock for 300 ms
else { // If not, show that the ID was not valid
Serial.println("error opening test.txt");
// close the file:
else {
// if the file didn't open, print an error:
Serial.println("error opening test.txt");

example :

card_id is 0908823

it will print :


Please respect. Thank you and God bless. :slight_smile:

Why do you break out of the while loop when you compare a record, regardless of whether or not a match was found?