Saturday 14 September 2013

Why is it that I can't use == in a For loop?

Why is it that I can't use == in a For loop?

I don't know if that's been asked before, but I haven't been able to find
an answer, nonetheless. My question is this; in For loops, this is
acceptable.
int k = 0;
for (int i = 0; i <= 10; i++)
k++;
But this is NOT:
int k = 0;
for (int i = 0; i == 10; i++)
k++;
Why is it that I cannot use '==' to determine whether the condition has
been met? I mean, both expressions return true or false depending on the
situation and the latter would be appropriate for, say, an If loop.
int k = 10;
if (k == 10)
{
// Do stuff.
}
The answer to this question has been bothering me for a good while now
during my time as a hobbyist programmer, but I hadn't searched for it till
now.

No comments:

Post a Comment