for(expr1; expr2; expr3)
{
statement;
}
next statement;
等同于:
expr1;
while(expr2)
{
statement
expr3;
}
next statement;
例如:
#include <stdio.h>
#include <string.h>
int main()
{
unsigned long hval=0;
char *key="alpha";
char c;
int i;
for(i=1;(c=*key++)!=0;i++)
{
printf("c is %d\n",c);
hval+=c*i;
printf("hval is %ld\n",hval);
}
}