Stop Command

Hello all!
I am trying to stop this do while loop when I type on or off. I just want to stop the display of integer that is been displayed.

int led = 13; // Pin 13
int a = 1;
int b = 2;
int c = 11;
int d = 12;
  void setup()
  {
      pinMode(led, OUTPUT); // Set pin 13 as digital out
 
     // Start up serial connection
     Serial.begin(9600); // baud rate
     Serial.flush();
 }
 
 void loop()
 {
     String input = "";
 
     // Read any serial input
     while (Serial.available() > 0)
     {
         input += (char) Serial.read(); // Read in one char at a time
         delay(5); // Delay for 5 ms so the next char has time to be received
     }
 
     if (input == "on"||input=="ON"||input=="On")
     {
          // on
         do {
          if (input =="off"){
          break;
          }
          digitalWrite(led, HIGH);
          Serial.print(a);
         Serial.print(",");
         Serial.print(b);
         Serial.println("");
         delay(300);
         } while(input == "on"||input=="ON"||input=="On");
     }
     else if (input == "off" || input =="OFF"||input=="Off") {
      do {
        if (input =="on"){
          break;
          }
         digitalWrite(led, LOW); // off
         Serial.print(c);
         Serial.print(",");
         Serial.print(d);
         Serial.println("");
         delay(300);
         
      } while (input == "Off"||input=="off"||input=="OFF");
    }
}

So what's the problem?

.

I want to get out of the do while loop once either I type on or off on the serial monitor.

You will need request the moderators to move your programming question from the installation section to the programming section. Then redesign the program so that you can read from the serial port while in the do loop.

I am sorry. I don't quite understand your response.

(a) Your question has nothing to do with the section (Installation) that you have posted it in. It should be in programming questions where more programmers would see it.

(b) Map out your program on paper.

Your program is in three sections:

  1. Read serial port
  2. Loop until serial input == ON
  3. Loop until serial input == OFF

Sections 2 and 3 loop until the serial input in section 1 changes. But if you are in section 2 or 3 waiting for the serial input to change when do you leave to back to section 1 to get new input? You have built yourself a big catch-22 program. You can't read the serial input until it changes which can't be changed until you read it which can't be read until it changes which can't be changed until you read it which can't read until it changes............

Alright. I will keep that in mind. Thank you!

Do you see the issue with how the program is written?

I don't sir.

So can anyone help me? Please.

I don't understand why you need a DO...WHILE loop inside your IF ?

Compare input string and do what you need to.