How do I start and stop a loop?

With an Arduino uno, I have created a block code to make a very cool LED animation that loops over and over. Also, I have written code to decode IR signals sent by a remote control to an IR receiver connected between +5v and pin 11. Every time the loop of code is run, the IR decoder returns a number specific to the button pressed on the remote. This numerical value is then stored as a variable (h). I would like the block of LED animation code to loop endlessly until a certain value of (h) is returned by the IR decoder. When this value of (h) is returned, I would like the Arduino to switch to another loop of code that will turn all the LEDs off. In this loop, when a certain value of (h) is returned, I want the Arduino to switch back to the original loop of LED code and play the animation, and run it until a certain value of (h) is returned, then so on. Can someone please show me how to do this? Thanks!!! :slight_smile:

Take a look at how the if-else and switch keywords are used in C.

Posting your existing code would make people's explanations more specific.

Generally, 'if' statements are used to select blocks of code to run or not run. Alternatively you can add a condition to a loop to stop (or not start) if the condition is not true.

Put the different blocks of code in separate functions and have a system in loop() to call them - something as simple as this

void loop() {
   readAndSaveIRvalue();
   if (irValue == 'a') {
      patternA();
   }
   else {
     patternB();
   }
}

Have a look at Planning and Implementing a Program

...R