Nested Do While loop
RoHerman00
Posts: 22
If you have a Do While loop like the one I have written out will it execute the most nested Do While first (in other words the While loop which turns on led1) then it will pause for half a second then turn on led2 pause for another half a second then finally turn on led3 pause for half a second and then turn off all the leds at the end?
i = 1
Do
high led3
pause 500
i = i + 1
Do
high led2
pause 500
i = i + 1
Do
high led1
pause 500
i = i + 1
while i < 2
while i < 3
while i < 4
low led1
low led2
low led3
Thanks,
Robert
i = 1
Do
high led3
pause 500
i = i + 1
Do
high led2
pause 500
i = i + 1
Do
high led1
pause 500
i = i + 1
while i < 2
while i < 3
while i < 4
low led1
low led2
low led3
Thanks,
Robert
Comments
If you enclose your code in CODE directives when you paste it, the tab spaces will be kept.
Like this:
Press the "#" button on your message editor (you may have to "go advanced").... then paste your code between the two CODEs:
[C0DE]
paste your code here
[/C0DE]
I strongly suggest that you re-read the section of the Stamp Manual on the DO / WHILE statement(s) and that you try pretending that you're a Stamp executing your program. Use a piece of paper. Start with the first line of your program and copy it to the paper, then "execute it" by writing any changes in any variables on the line that you copied. Then decide what line of your program will be executed next and write that down on the next line, repeat.
Remember that
is equivalent to
I'm not sure what you intended, but it WILL execute even though it is a little Rube Goldberg for turning on three LEDs. In other words, it could be simplified considerably.
Remember your "led#" needs to be identified for the BS to understand what it means. I figure you already know that however.
In reply to spiral_72 it isn't going to be turning on leds I just wanted to know if it would execute that way. The program I wrote is much more than that but it works basically the same way. And thanks for showing me how to post code.