+ 3
Why this code is showing an error? Pls. Help
But after removing the semicolon ; from the end of the for loop it has no error why so? #include <iostream> using namespace std; int main() { for(int i=0;i<7;i++); cout<<i; return 0; }
2 Answers
+ 9
Because you have declared i inside for loop and is not accessible outside the scope of that for loop.
Correct code.
#include <iostream>
using namespace std;
int main() {
int i;
for(i=0;i<7;i++);
cout<<i;
return 0;
}
+ 1
the for loop doesn't have a semicolon at the end