Loop Count

Here is my code. The purpose of this code is to have it read the "if" statements a certain amount of times, in this case 11 times, and once it has reached a certain loop count, to have it shut off. I implemented the "while" statement to make that happen but it instead takes my count for the if statements and starts it at 13.

int led = 12;
int led1 = 11;
int cnt = 1;
int del;
void setup() {
// put your setup code here, to run once:
Serial.begin (9600);
pinMode (led,OUTPUT);
pinMode (led1,OUTPUT);
}
void loop() {
// put your main code here, to run repeatedly:
{
{ while (cnt <=11) cnt++;}{

if (cnt <= 3 and cnt > 0) {del = 1500;}

if (cnt > 3 and cnt <= 6) {del = 1000;}
if (cnt > 6 and cnt <= 9) { del = 500;}
if (cnt > 9 and cnt <= 12) {del = 250;}
if (cnt > 12 and cnt <= 15) { del = 125;}

if (cnt > 15 and cnt <= 18) {del = 1000;}
if (cnt > 18 and cnt <= 21) { del = 500;}
if (cnt > 21 and cnt <= 24) {del = 250;}
if (cnt > 24 and cnt <= 27) { del = 125;}
if (cnt == 27) {cnt = 1;}
}
}
digitalWrite (led, HIGH); //Turn on red LED
delay(del);
digitalWrite (led, LOW); //Turn off green LED
delay (del); //Delay
digitalWrite (led1, HIGH); //Turn on green LED
delay(del);
digitalWrite (led1, LOW); //Turn off red LED
delay (del); //Delay
cnt++; //Add count
Serial.println(cnt); //To read count

There is all sorts of wrong in that code.

Where did you get it?

I wrote it :confused:

 { while (cnt <=11) cnt++;}{
 
 if (cnt <= 3 and cnt > 0) {del = 1500;}

While cnt is less than or equal to 11, uselessly increment it one step at a time. You might as well have:

   cnt = 12;

there.

What do you suppose the if statements will evaluate to?

I tried putting in cnt = 12 and the leds did not turn on at all. I'm assuming I should be using something other than cnt since that is supposed to count the blinks on the LED. Should I be declaring the loop count as a different variable?

What exactly is this code suppose to do?

So basically I want this code to turn on and off the two LED's at different delays going back and forth between the two LED's for a certain amount of times at different delays. I wanted to implement the "while" statement to tell the loop to stop once it has looped a certain amount of times. Maybe I am mistaken on how a loop statement works?

The code in the demo Several Things at a Time illustrates how to make a few LEDS flash at different times.

...R