arduino - modem communication

I have an Arduino Uno sending and receiving data from a GPRS modem and the modem works with AT commands.

//I want:

arduino to write command_1 to modem
Wait for the answer from modem
read serial port
check if command successful (i.e modem sends OK if successful and ERROR if there is an error)

If there is an error, resend command_1

if successful
then
Write command_2 to modem
Wait for answer
read again serial port
check if command is succesful (modem again sends OK if successful and ERROR if there is an error)

so far this is where i went

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

void loop() {
  Serial.print("command_1");
  String myString = "";
  char inChar; 
  char iChar;
  String mString;
  while(Serial.available() > 0)
  {
    inChar = Serial.read();
    myString += inChar;
    Serial.print(inChar); 
  }
 while (myString != "OK") {
    Serial.print("command_1");  
   }
   
   Serial.print("command_2");
   while(Serial.available() > 0)
  {
    iChar = Serial.read();
    mString += iChar;
    Serial.print(iChar); 
  }
 while (mString != "OK") {
    Serial.print("command_2");  
   }
}

so far the code is compiling but its not comparing.

Let's take a look at your code:

  Serial.print("command_1");
  String myString = "";
  char inChar; 
  char iChar;
  String mString;
  while(Serial.available() > 0)
  {
    inChar = Serial.read();
    myString += inChar;
    Serial.print(inChar); 
  }
 while (myString != "OK") {
    Serial.print("command_1");  
   }

You send the command, then immediately check if the device has answered. It probably hasn't because you're sending with 9600 baud, there is a high probability that not event the first character was sent at this time. So your sketch continues with the while loop where it checks if the (most probably empty) string object myString is unequal to "OK". As this is the case, it sends the command again (or better it fills the outgoing buffer with it) and checks if the same string (it hasn't changed in the loop) is still unequal to "OK". Surely it is, so it fills the buffer again with the command, and so on.
I hope you got the hint.

Are you using Serial to talk to the PC or to talk to the modem? Both is the wrong answer.