Basic question. Can i have two ore more loops?

Hi,
I have a potentiometer and want it's value from 0 to 1023 choose what loop to go to. The different loops are named after the colors. If value of the potentiometer is 0 to 70 goto red, if value is 71 to 140 go to greed etc. Any ideas? Can i hava different loops that only can be interupted by the potentiometrs value or what can i do? right now ony red works and if i call green in the potentiometer it gives me all the "colors".

int potPin = 2;    // select the input pin for the potentiometer
int ledPin1 = 13;   // select the pin for the LED
int ledPin2 = 12;
int ledPin3 = 11;
int ledPin4 = 10;
int val = 0;
const int red = 0;       // variable to store the value coming from the sensor
const int green = 70;       // variable to store the value coming from the sensor
const int blue = 140;       // variable to store the value coming from the sensor
const int cyan = 210;       // variable to store the value coming from the sensor
const int yellow = 280;       // variable to store the value coming from the sensor
const int purple = 350;       // variable to store the value coming from the sensor
const int white = 420;       // variable to store the value coming from the sensor
const int color7change = 490;       // variable to store the value coming from the sensor
const int color7flow = 560;       // variable to store the value coming from the sensor
const int color7fade = 630;       // variable to store the value coming from the sensor
const int color7drm = 700;       // variable to store the value coming from the sensor
const int mix7colorskip = 770;       // variable to store the value coming from the sensor
const int singlecolorflow = 840;       // variable to store the value coming from the sensor

void setup() {
  pinMode(ledPin1, OUTPUT);  // declare the ledPin as an OUTPUT
    pinMode(ledPin2, OUTPUT);  // declare the ledPin as an OUTPUT
      pinMode(ledPin3, OUTPUT);  // declare the ledPin as an OUTPUT
        pinMode(ledPin4, OUTPUT);  // declare the ledPin as an OUTPUT
}

void loop() {
  
  val = analogRead(potPin);    // val får värdet från potentiometern mellan 0 och 1023

if (val > red) {

//RED
  
  digitalWrite(ledPin1, LOW);  // turn the ledPin on
//  delay(val);                  // stop the program for some time
  digitalWrite(ledPin2, HIGH);   // turn the ledPin off
// delay(val);                  // stop the program for some time
  digitalWrite(ledPin3, HIGH);  // turn the ledPin on
// delay(val);                  // stop the program for some time
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off
// delay(val);                  // stop the program for some time

//val = analogRead(potPin);    // läser in nytt aktuellt värde från potentiometer och sparar i val
} 

if (val > green) {

//GRÖN

  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  digitalWrite(ledPin2, LOW);   // turn the ledPin off
  digitalWrite(ledPin3, HIGH);  // turn the ledPin on
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off

} 

// val = analogRead(potPin);    // läser in nytt aktuellt värde från potentiometer och sparar i val

 if (val > blue) {

//BLUE

  digitalWrite(ledPin1, LOW);  // turn the ledPin on
  digitalWrite(ledPin2, LOW);   // turn the ledPin off
  digitalWrite(ledPin3, HIGH);  // turn the ledPin on
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off

}

 if (val > cyan) {

//CYAN

  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  digitalWrite(ledPin2, HIGH);   // turn the ledPin off
  digitalWrite(ledPin3, LOW);  // turn the ledPin on
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off

}


 if (val > yellow) {

//YELLOW

  digitalWrite(ledPin1, LOW);  // turn the ledPin on
  digitalWrite(ledPin2, HIGH);   // turn the ledPin off
  digitalWrite(ledPin3, LOW);  // turn the ledPin on
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off

}


 if (val > purple) {

//PURPLE

  digitalWrite(ledPin1, HIGH);  // turn the ledPin on
  digitalWrite(ledPin2, LOW);   // turn the ledPin off
  digitalWrite(ledPin3, LOW);  // turn the ledPin on
  digitalWrite(ledPin4, HIGH);   // turn the ledPin off

}

}

You can have 1 loop only.

You write functions to do various things and call them from loop();

You will probably find these helpful, especially the second one:
Using millis for timing
Demonstration for several things at the same time

Use a more complex if statement to select actions corresponding to a range of values

if (val >= redLowerLimit && val <= redUpperLimit) {
...

if you're going to test a value for different ranges you need to sequentially test the ranges starting from highest to lowest. your first test is "val > red", but red is zero, so it is always true.

you need to start with "singlecolorflow" and work sequentially to red if you're testing for ">"

The other issue at hand, is how fast do you think the loop is running?

When val > purple, then all the other statements are true as well. So the digitalWrite commands for red, green, blue, cyan , yellow and purple all execute. Then the code starts back at the top immediately. The four output pins are turning on and off so fast you cannot see it. I do not know how you leds work or what they are, but it might need to be considered that only one of the color statements is true at a time. So each statement should be written

if ((x<val) && (val<y))
{ digitalWrites }

Hi again,
The change of order, red = 0 last and the && >= (high and low range for each color) solved my problem. BIG Thanks!!

/Nossanoj