Well, there are several careless errors in the code. If we first debug it and correct the errors, we get this code:
1 2 3 4 5 6
int strlen(constchar* s)
{
int i;
for (i=0; s[i]; i++);
return i;
}
the s[i] is the condition to be tested, just the same as in any other for loop.
The code is equivalent to:
1 2 3 4 5 6 7
int strlen(constchar* s)
{
int i = 0;
while (s[i])
i++;
return i;
}
The loop will execute while the condition (s[i]) is true. This follows the normal rules, that a non-zero value is true and a value of zero is false. Hence the loop will execute until the zero byte is found which marks the end of the string.