Equality test as second parameter to for loop

Why does this work - outputs 1 to 10 and the message

void setup() 
{
  Serial.begin(9600);
  for (int i = 0; i <= 10; i++)
  {
    Serial.println(i);
  }
  Serial.println("loop done");
}
void loop() 
{

and this fail - no number output, only the message

void setup() 
{
  Serial.begin(9600);
  for (int i = 0; i == 10; i++)
  {
    Serial.println(i);
  }
  Serial.println("loop done");
}
void loop() 
{

I would have expected it to loop until i equalled 10 but it doesn't

Let's rewrite it as the equivalent while-loop...

void setup() 
{
  Serial.begin(9600);

  int i; 

  i = 0;

  while ( i == 10 )
  {
    Serial.println(i);

    i++;
  }

  Serial.println("loop done");
}

Does that help?

Answering my own question after some thought.

It is because the loop continues while the condition is true, not until the condition is true

Confusion with other programming language is my excuse.
Sorry to have bothered you all.

Thanks CB - I realised the answer almost immediately after posting my question.

The for loop is also often used for an infinite loop

for(;:wink:
{
... do your thing
}

so the empty(?) statement appears to evaluate to true.

UKHeliBob:
Why does this work - outputs 1 to 10 and the message

void setup() 

{
  Serial.begin(9600);
  for (int i = 0; i <= 10; i++)
  {
    Serial.println(i);
  }
  Serial.println("loop done");
}

Doesn't this actually output 0 ... 10 and not 1 ... 10?

0
1
2
3
4
5
6
7
8
9
10
loop done

Yes Rob, I got the point, but didn't think it worth replying.

Perhaps I should have done in case someone else stumbled upon the thread and was confused.

Sorry, the problem as I saw it was who is confused? I know it wasn't me!

Nor me, but if it was not clear that Rob was right (0 - 10) and I was wrong (1 - 10) some future reader of the thread might not know which was correct.