function to restart looping?

hay… there is function to restart looping

example…

int val = analogRead(1);

void loop()
{
digitalWrite(led, HIGH);
delay(1000)
digitalWrite(led, LOW);
delay(1000)
digitalWrite(led2, HIGH);
delay(1000)
digitalWrite(led2, LOW);
if (val == 5)               <============= if val = 5 restart looping from begining
{   restart looping from begining      }
delay(1000)
digitalWrite(led3, HIGH);
delay(1000)
digitalWrite(led3, LOW);
delay(1000)
}

there is function to do it?

It is ugly and not recommended but you could use a goto statement. Always better to restructure your code so that the condition that causes the looping is in the loop statement, if that makes sense.

return;

Couldn’t you just say

if(val !=5){

// all the other stuff

}

ase123:
int val = analogRead(1);

Is a bad idea. The hardware has not been initialized at the point analogRead is called. Move the initialization to setup where it belongs.

void loop() {
	int loopVal;

	while (1){
		loopVal=1;
	
		while (analogRead(1)!= 5) {
			switch(loopVal)	{
				case 1:
					digitalWrite(led, HIGH);
					loopVal++;
				case 2:
					digitalWrite(led, LOW);
					loopVal++;
				case 3:
					digitalWrite(led2, HIGH);
					loopVal++;
				case 4:
					digitalWrite(led2, LOW);
					loopVal++;
				case 5:
					digitalWrite(led3, HIGH);
					loopVal++;
				case 6:
					digitalWrite(led3, LOW);
					loopVal=1;
			}
			delay(1000);
		}
	}
}

@Arrch

yeah the function return; is work..

thanks for all

inner loop can be shortened by using bitmasks.

    while (analogRead(1) != 5) {

			switch(loopVal)	{
				case 1:
					digitalWrite(led, HIGH);
					loopVal++;
				case 2:
					digitalWrite(led, LOW);
					loopVal++;
				case 3:
					digitalWrite(led2, HIGH);
					loopVal++;
				case 4:
					digitalWrite(led2, LOW);
					loopVal++;
				case 5:
					digitalWrite(led3, HIGH);
					loopVal++;
				case 6:
					digitalWrite(led3, LOW);
					loopVal=1;
			}
			delay(1000);
		}
while (analogRead(1) != 5) 
{
  if (loopVal & 0x01) digitalWrite(led, HIGH);
  else digitalWrite(led, LOW);
  loopVal++;
  if (loopVal == 6 ) loopVal=1;
  delay(1000);
}
 (analogRead(1) != 5)

Am I the only one who thinks this is a really bad idea?

yeah 5 is such a magic number, one should use a #define for that :wink:

#define MAGICNUMBER 5
...

(analogRead(1) != MAGICNUMBER )

but then, it might be just what the OP intended ...

No, not the magicness, just the precision, from an analogue input.