How can I stop for loop by a comand

Hi to everybody…

I played different ways still did get it right… How the hall I can stop for loop by a command?
I can start the FOR loop by command no problem… I can use for that Serial.peek. Serial.read()==‘1’

But I need and i can not to interrupt and stop the FOR loop by command. What i do???

This code doesn’t work. I mean the for loop running untill 10 i need stop on 4 or 5 by command

  while(Serial2.available()>0)
       {
        char Ch = Serial2.read();
        int j=0;
     
          if(Ch == '1')
            {      
              for(j; j<10; j++)
                 { 
                   Serial1.println("ATZ");
                   delay(3000);
                   
                       if(Serial1.available()>0)
                         {
                           getResponse();                    
                           Serial2.println(str);
                           Serial2.println(str.length()); 
                          }
                 }  
              }
              else if(Ch == '0')
                      {
                        j=10;
                        delay(100);
                      }
   }
}
break;

Break ain’t work ether. I guess Im not putting it in right place

  while(Serial2.available()>0)
       {
        char Ch = Serial2.read();
        int j=0;
     
          if(Ch == '1')
            {      
              for(j; j<10; j++)
                 { 
                   Serial1.println("ATZ");
                   delay(3000);
                   
                       if(Serial1.available()>0)
                         {
                           getResponse();                    
                           Serial2.println(str);
                           Serial2.println(str.length()); 
                  
                         }
                         
                         
                     if(Ch == '0')
                      {
                        j=0;
                        break;
                       } 
                 }
   }}
}

How the hall I can stop for loop by a command?

Do you mean stop it or make it finish early. 1) You can not stop it. 2) If you make it finish early then it will only start again.

Basically if you think you want to do this then you are not structuring your code correctly.

Ok I need for loop to run part of the code constantly.. Why i need to stop the for loop is switch it to another part of the code which also will be using for loop...

I using for loop for constant update or read the info from serials I will have 2 difren serials with incoming data on them. So I need run them on the same sketch.. something like that so...

Ok I need for loop to run part of the code constantly..

Isn't that what the loop() function does for you ?

I using for loop for constant update or read the info from serials I will have 2 difren serials with incoming data on them. So I need run them on the same sketch.

You do not need 2 different for loops, or even one for loop, to read from 2 different serial inputs.

It sounds like you need to structure your code as a state machine, like that in the blink without delay example.