code block question

what is the code for repeating a block of code, say i made a 3 blocks of code for led sequenced at code1 then code 2,then code 3; then i want to repeat again code 2 after code 3. tnx guys

Do you want a 'for' loop?

A AWOL states the for and while are the once to look for in the reference section.
For and while are practically identical and most for loops can very easily be rewritten with a while (and vv).
For loops are traditionally more used for fixed nr of iterations and while for unknown nr of iterations but that is only a historical difference.

The while has also the do ... while variation that runs through the loop at least once.

for (int i=0; i< 10; i++)
{
  code1;
  code2;
  code3;
}
int i=0;
while (i< 10)
{
  code1;
  code2;
  code3;
  i++
}
int i=0;
do {
  code1;
  code2;
  code3;
  i++
} while (i< 10)

endless loop:

for(;;)
{
  code1;
  code2;
  code3;
}
while(true)
{
  code1;
  code2;
  code3;
}

Or...

cycle:

//some code

goto cycle;

Although I wouldn't recommend it.

Although I wouldn't recommend it.

especially not recommended when the label: is in setup() and the goto is in loop() :slight_smile: