In my setup I have connected two arduino's Serially. An Arduino Mega is the on that is sending the string and a Arduino Uno is the one receiving it.

Arduino Mega : TX1(19),RX1(18) - Serial1 
Arduino Uno : RX(10),TX(11) - using SoftwareSerial

When I send a single string from the mega to Uno multiple times(In void loop)
I receive the string sent infinite number of times on the Uno which is to be expected:

<b>Arduino Mega - Single string sent multiple no. of times</b>

 void setup()
 {
 Serial1.begin(9600);
 }
 void loop() 
 {
 Serial1.println("e2e4"); 
 delay(100);
 }

Now I want to only send the string a single time, so I inserted an exit(0) or an infinite loop after the delay that is always true. 

<b>Arduino Mega - Single string sent only one time</b>

 void setup()
 {
 Serial1.begin(9600);
 }
 void loop() 
 {
 Serial1.println("e2e4"); 
 delay(100);
 while(true);
 } 

<b>Arduino UNO - code is same for both cases</b>

 #include <SoftwareSerial.h>
 SoftwareSerial s(10, 11);
 void setup() 
 {
 delay(200);
 Serial.begin(9600); 
 s.begin(9600);
 while (!Serial) ; // wait for Arduino Serial Monitor 
 }
 void loop() 
 { 
 if(s.available()>0)
 {
 Serial.print("\nrec\n");
 delay(100);
 String b = s.readStringUntil('\n');
 delay(100);
 Serial.print(b);
 delay(40);
 }
 }

Note : Arduino uno is receiving the string using : readStringUntil('\n')

But when I send the string only once I receive nothing on the Arduino Uno, can anyone help me figure out why this is happening

<b>What I want to know is why the uno receives the string only when it's sent an infinite number of times and not when it is sent 1 time.</b>