lgore93
2012-07-26 08:52:05 UTC
My code:
#include
int main()
{
int number = 0;
printf("%d\n", number);
for (int i = 0; i < 25; i++)
{
printf("%d\n",i);
}
return 0;
}
I'm running this in Visual C++ Express, and it's going crazy over me declaring and initializing "i" in the for variable all at once. Am I maybe leaving something out? In Java, this is the standard way to create a for loop.
I thought that maybe since I'm using the Visual C++ compiler, it was somehow not compiling correctly. If I declare i from outside the loop, everything works fine. I made the first line (int number = 0) to make sure that variables can be initialized as they're declared. This has me stumped.
Note: Yes, I'm using the C compiler of Visual C++, so this can't be the problem.
Error list from build attempt:
1>hey.c(7): error C2143: syntax error : missing ';' before 'type'
1>hey.c(7): error C2143: syntax error : missing ';' before 'type'
1>hey.c(7): error C2143: syntax error : missing ')' before 'type'
1>hey.c(7): error C2143: syntax error : missing ';' before 'type'
1>hey.c(7): error C2065: 'i' : undeclared identifier
1>hey.c(7): warning C4552: '<' : operator has no effect; expected operator with side-effect
1>hey.c(7): error C2065: 'i' : undeclared identifier
1>hey.c(7): error C2059: syntax error : ')'
1>hey.c(8): error C2143: syntax error : missing ';' before '{'
1>hey.c(9): error C2065: 'i' : undeclared identifier