Reputation: 3
This prints 100 and "counter is Active." but will not print any text that is associated with the for loop.
I have attempted this in Code::Blocks and Microsoft Visual 2010 Express (both with the same results).
Apologies if this is inane, I just started trying to learn C++ a few days ago.
#include <iostream>
using namespace std;
int main()
{
int ram = 100;
cout << ram << endl;
cout << "counter is Active." << endl;
for (int counter = 0; counter > 10; counter++)
{
cout << "counter is not greater than 10." << endl;
cout << "counter is " << counter << endl;
}
return 0;
}
Upvotes: 0
Views: 164
Reputation: 2646
Your loop conditions are wrong...
Change your loop to
for (int counter = 0; counter < 10; counter++)
Your loop was previously
for (int counter = 0; counter > 10; counter++)
Which says continue looping while counter is greater than 10. Since counter starts at zero, it is never greater than 10, and so the code in the loop never executes.
Upvotes: 2