I wanted to control my servo with my switch from Arduino Cloud

The problem may be my: For loop(). if i press switchOn servo Starts and 2nd time I press SwitchOn to off I want my servo to stop but it stops only after it comes to o Positio . Is there a way i could control my servo . I mean when i press switch 2nd time i want it stopped before it goes to start position ie 0.

<<<if(switchOn)
{
for(pos = 0; pos <= 180; pos += 1) // von 0 bis 180 Grad, in Schritten von einem Grad
{

  myservo.write(pos);                   // sagt dem Servomotor, in welche Position sich drehen soll      

  
  delay(15);                            // wartet 15 Millisekunden 
  
  
 
}

for(pos = 180; pos>=0; pos-=1) {        // und das gleiche zurück

  myservo.write(pos);

  delay(15);
  


}
  }>>>

Your program doesn't read the switch while the servo is moving, therefore with such a code is not possible to stop the servo before it goes to the end. The logic of your actual program is something called "blocking", because the code is blocking in the for loop until it finished.

To solve that you need to change the logic of the program. Look to the "BlinkWithoutDelay" example in the IDE. Read something about "finite state machines".

Your code is not a complete sketch and looks awful
too much empty lines. improper indention

.
.
To learn about non-blocking timing