1. ## nested four loops

ok so what i am trying to do is have an led flash on and off at one speed and then flash at at another speed for a set period of time...i am pretty sure that i need two for loops to do this but i am not sure how this works

i would like to have the first for loop just flash the led four times and then have the second for loop flash the led 8 times

the leds flashing time is determined by an interrupt and the is working correctly...i just need help getting the for loops to work

Code:
```int i=0, j=0

for(i=0; i<4; i++){
if(G_Flag){
led on;
}
else{
led off;
}
i++;
}if(i=4){
for(i=4;i<8<i++) {
if(G_Flag)
led on;
else
led off
i++
}
}
i=0
}
interrupt_ISR
{
G_Flag = !G_Flag
}```
the way i am controlling the leds is not an issue i have that underwraps but i am not sure how to just have the led flash on four four times and the have it flash on again at a different speed for eight times

i thought that this code would work because once i is equal to four it would go into the second for loop but it doesn't work and i don't understand why

2. You would have to call interrupt_ISR once in each for loop to negate G_Flag. Also, in the second for loop, you typed "if" instead of "for".

3. Code:
```for(i=0;i<12;i++) {  //12=number of total flashes I want
if(i<4)  //4=number of long flashes I want
longFlash
else
shortFlash
}```
Both 4 and 12 in the above could be defined macros:
#define LONG_NUM 4
#define FLASHES 12

or just variables.

4. the only problem i have is that i am using a mciro controller and not programming in visual studies so i don't know if i can use the long number of any of thoes macros that you could typically use in c, but may i am not sure

5. In that case, "magic" numbers are OK.

You may need to use two different loops. No if(i == 4) is needed, since i will always equal 4 at the end of the first loop.

6. that what im confused about...i am not that familar with c, the only real programming classes i have had is c++ what i was thinking is that the...

the first for loop would count up, to four, and then once it hit four, it would kick into the second four loop?

7. that what im confused about...i am not that familar with c, the only real programming classes i have had is c++ what i was thinking is that the...

the first for loop would count up, to four, and then once it hit four, it would kick into the second four loop?

8. Originally Posted by begginer
that what im confused about...i am not that familar with c, the only real programming classes i have had is c++ what i was thinking is that the...

the first for loop would count up, to four, and then once it hit four, it would kick into the second four loop?
The first loop could count up to four, and then it would kick over into the second for (you almost got me to write "four" loop.

But you don't need the test for i == 4 in there. After the first loop, I will always be four. No test needed.

This is an error, since = is for assignment anyway. Inside an if statement, you need == (and anywhere else you test for equality.

Code:
```if(i=4){  //wrong. Should be deleted, anyway.

if(i==4) { //correct syntax for a test of equality. Not needed before the second for loop in your code.```

9. lol, i guess that is to many "for" and "four" in one issue but i got it to work...thanks for all the help

10. "to many"

You are KILLING me here!

"to many"

You are KILLING me here!
C'mon Adak... fore loops are fun!

12. It's "to" mulch for me "too" bare!

Hello!