• Advertisement

Archived

This topic is now archived and is closed to further replies.

for loop woes

This topic is 5237 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Why does this only print out the first numbers?

int Array[2][2] = {1, 2,
                   3, 4};
 int x = 0;
 int y = 0;

 for(; x < 2; ++x)
  for(; y < 2; ++y)
   std::cout << Array[x][y] << std::endl;

but this prints out the whole array.

int Array[2][2] = {1, 2,
                   3, 4};

 for(int x = 0; x < 2; ++x)
  for(int y = 0; y < 2; ++y)
   std::cout << Array[x][y] << std::endl;

I''m using Visual C++ .NET 2003

Share this post


Link to post
Share on other sites
Advertisement
Because the first one never resets y, the second one does.

[edited by - Chozo on October 24, 2003 1:28:04 PM]

Share this post


Link to post
Share on other sites

  • Advertisement