how to run a code once in the void loop?

how to run a code once in the void loop setup?
my aim to get a number from my sim card (eg 1234) and open the file in sd card of that name (1234.txt)

#include <SoftwareSerial.h>
#include<LiquidCrystal.h>
LiquidCrystal lcd(2,3,4,5,6,7);
#include <SPI.h>
#include <SD.h>

File myFile;

SoftwareSerial mySerial(9, 10);
String c,r,t,e,x,m="1234";
String array[50];
int index=0;
void setup() {
  lcd.begin(16,4);
  // put your setup code here, to run once:
mySerial.begin(9600);   // Setting the baud rate of GSM Module  
  Serial.begin(9600); 
 mySerial.println("AT+CPBR=1");

  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(8)) {
   
    Serial.println("initialization failed!");
    return;
  }
  Serial.println("initialization done.");
 
}

void loop() {
  
 
  if (mySerial.available()) 
 { c = mySerial.read();
array[index]=c;
index++;
array[index]="0";
e=array[24];
r=array[25];
x=array[26];
t=e+r+x;
 myFile = SD.open(m+".txt");
  if (myFile) {

  if(myFile.available())
  {
    
  }

    // read from the file until there's nothing else in it:
    while (myFile.available()) {
      
       Serial.write(myFile.read());

    }
    // close the file:
    myFile.close();
  }
}}

iam getting correct output but it runs like 20 times
eg: hii
hii
hii
.
.
.

.
hii

like this . i want to run it once and show it in the lcd display

ple help me

Declare and set a global variable (say boolean hasRun = false). Put the code that you want to run once in a function. In loop() read the state of hasRun and if false execute the function (if(hasRun == false) runFunction()). Inside the function, set hasRun to true. The next time through loop() hasRun is true and the function will not ever execute again.

If you only want it to run once, put the code in setup

AWOL:
If you only want it to run once, put the code in setup

i put the code in loop but it doesnot work

So put the code in setup, not loop

You can make your code easier for us to read by using Ctrl-T in the IDE before posting. Also, things that are used to initialize objects (Initialization Step) are often best placed in the setup() function, as AWOL said. See this for details.

sorry prevous comment was a mistake i have put the code in setup but it doesn't work

sir iam new in programming .can you correct my proggram plz?

i have put the code in setup but it doesn't work

So, you did something wrong. (BTW, saying "it doesn't work" isn't helpful)

void setup() {
  // set up the LCD's number of columns and rows:
 Serial.begin.begin(16, 2);
  // Print a message to the LCD.
  
}

void loop() {

Serial.print("hello, world!");

}

here this hellow world print several time . how to print it one time in the void loop (without in setup() )

See reply #1. Or put the print in setup, where it will be executed just once per reset.

sir i don't know how to set glbal variable plz could you just corret my prograam

i want i to put in loop()

boolean didMyOneTimeAction = false;

void setup() {
  Serial.begin(115200);
}

void loop() {
  if (didMyOneTimeAction == false)
  {
    didMyOneTimeAction = true;
    Serial.print("Hello World");
  }
}

Good grief! Put the statement in setup() or flag it in loop():

#include <LiquidCrystal.h>

int passFlag = 0;
LiquidCrystal lcd(12, 11, 7, 6, 5, 4);  // Create an LCD object using the pins you've wired to it

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(16, 2);     // This initializes the LCD object, not the Serial monitor
  Serial.begin(9600);   // This initializes the Serial monitor
}

void loop() {
  if (passFlag == 0) {
    Serial.print("hello, world!");  // Display on Serial monitor
    lcd.print("Hello world");       // Display on LCD display
    passFlag++;                     // Increment passFlag
  }
}

Now, go read a beginning Arduino C programming book

it works thanku u both of you