IS there an example that switches (digital IN) between loops of code to be run?

Simple problem at hand here. Is there example out there that switches between two loops of code to be run? In other words:

digital pin HIGH run
Loop 1

digital pin LOW run
Loop 2

if (condition) {
do_some_things();
}
else{
do_some_other_things();
}

jremington:

if (condition) {

do_some_things();
}
else{
do_some_other_things();
}

Ha ha... ok thanks. It's that simple.

I will try it in the morning with something like blink every one second, else blink every half second controlled by a digital pin high or low. Wish me luck...

In that case just set the blink rate, depending on the state of the digital input. Everything else stays the same.

Ok I found a simple way to do it. Not the only or best way by any means, but it works. I used Blink and instead of infinite running of the single blink program I have a fast blink and a slow blink section; each run via 'for loops'. I can completely omit the fast blink 'for loop' via a digital input. This consists of borrowed sections of example "DigitalInputPullup".

Maybe this will help someone else doing something similar. I left a lot of the original commenting intact. It's obviously very beginner level on commenting obvious things, but why omit it. It's in the examples and other than bulk, it hurts nothing to leave it.

/*
  This program combines the stock 'DigitalInputPullup' example with the example
  'Blink' to use an input from an external switch to vary the amount of times 
  a 'for loop' is run. This can be done while the main loop is running. The 
  change occurs the next time through the loop (i.e. switching is not immediate).

  The switch is on digital input 2 which sets the value of int 'a' in order to change 
  the amount of times the 'short and fast' 'for loop' will loop. The switch pulls LOW.

'Short and Fast' for loop  
>>  Turns an LED on for 10ms and off for 30ms and loops 89 times (unless the switch cuts this short)

'Long and Slow' 'for loop'
>>  Turns an LED on for one second, then off for one second, 4x.

 ...

  Original 'Blink' and 'DigitalInputPullup' example code is in the public domain.
*/

// variable declarations
int q = 0; // variable to 'for loop' the fast blink 
int r = 0; // variable to 'for loop' the slow blink 
int a = 0; // variable to cut short (or remove) the fast blink 'for loop'

// the setup function runs once when you press reset or power the board
void setup() {
  //start serial connection
  Serial.begin(9600);
  //configure pin 2 as an input and enable the internal pull-up resistor
  pinMode(2, INPUT_PULLUP);
  // initialize digital pin LED_BUILTIN as an output.
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop function runs over and over again forever
void loop() 
{
  //read the pushbutton value into a variable
  int sensorValue = digitalRead(2);
  //print out the value of the pushbutton
  Serial.println(sensorValue);
  if (sensorValue == HIGH) {
    a = 65;  // cuts short the looping of fast blinks. Set it at 89 to completely eliminate it
  } else {
    a = 0;   // allows the full amount of fast blink looping
  }
  
{
for (q = 0; q <=(88-a); q += 1) // loops the fast blinks "q <= x" times. NOTE!!! subractor 'a' and see above
{  
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(10);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(25);                       // wait for a second
}

for (r = 0; r <=3; r += 1) // loops the slow blinks "r <= x" times.
{  
  // the loop function runs over and over again forever
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);                       // wait for a second
}
}
}