Hi I learning c++ through a book but I have found that one of the examples provided by the book is an infinite loop. So I was wonderring if anyoone can help me stop it. I tried using the 'break;' statement in every 'for' body to stop the loop but the results aren't what the book shows. So if any one can help me find the loop and end it but at the same time do not affect the the output of the program.
This is the code:
using namespace std;
int main()
{
cout << "Counting forward:\n";
for (int i = 0; i < 10; ++i)
{
cout << i << " ";
}
cout << "\n\nCounting backward:\n";
for (int i = 9; i >= 0; --i)
{
cout << i << " ";
}
cout << "\n\nCounting by fives:\n";
for (int i = 0; i <= 50; i += 5)
{
cout << i << " ";
}
cout << "\n\nCounting with null statements:\n";
int count = 0;
for ( ; count < 10; )
{
cout << count << " ";
++count;
}
cout << "\n\nCounting with nested for loops:\n";
const int ROWS = 5;
const int COLUMNS = 3;
for (int i = 0; i < ROWS; ++i)
{
for (int j = 0; j < COLUMNS; ++j)
{
cout << i << "," << j << " ";
}
cout << endl;
}
return 0;
}