For Trouble

hello, this is an old topic i might need to open another one. anyways.

i've been trying this:

for(i=10;i==0;i--){
xxxxx;
xxxxxx;
}

it doesn't work. any ideas?

it doesn't work. any ideas?

Your for statement says "Starting with i equal 10, while i equals 0, execute the body, and then decrement i.". That works, exactly as you wrote it.

If you think it doesn't work, you are wrong.

You need to post ALL of your code, and some description of what it actually does, along with some proof that it is not working as written.

There's a useful online reference to the Arduino features. You can get to it from the top of the page, Resources then Reference. The page about For has a detailed explanation of how that middle parameter works.

What you said is set i to 10 then immediately check that i is equal to 0. It isn't so the for loop ends.

Steve

PaulS:
Your for statement says "Starting with i equal 10, while i equals 0, execute the body, and then decrement i.". That works, exactly as you wrote it.

If you think it doesn't work, you are wrong.

You need to post ALL of your code, and some description of what it actually does, along with some proof that it is not working as written.

i see, yes i am wrong

so it should be
or
for (i=10;i!=0;i--){
or
for (i=10;i>=0;i--){

right?
thank you

slipstick:
There's a useful online reference to the Arduino features. You can get to it from the top of the page, Resources then Reference. The page about For has a detailed explanation of how that middle parameter works.

What you said is set i to 10 then immediately check that i is equal to 0. It isn't so the for loop ends.

Steve

and thank you steve

PaulS:
If you think it doesn't work, you are wrong.

That's because in most people's minds "It doesn't work" == "It doesn't do what I expect it to do"