+ 1
Expected primary-expression before ";" token
Error as above Im trying to write for loop that end when y reaches value of 2. What did i wrong? for (;(y == 2);;) { sth sth nevermind }
2 ответов
+ 3
You have an extra semicolon (;) in the 'for' statement. There should only be two semicolons in the 'for'. Without knowing the context, I would say that the last semicolon is your problem and the statement should be:
for (; y == 2; ) {
sth sth nevermind
}
If that is your intent, you could use a while statement like this:
while (y == 2) {
sth sth nevermind
}
0
It should look like this:
for(int y=0; y<=2; y++){
std::cout << y << endl;
}
Note that this loop will actually be executed three times, since the string value of y was zero, so the output will be:
0
1
2