Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


#ActualMarkS

Posted 06 December 2012 - 09:07 PM

To expand on what Alvaro said, nested loops do not run concurrently. The "column" for loop completes before control is given back to the "row" for loop. Another way of looking at that code snippet is:


for (row = 0; row < 5; ++row) {

	 cout << map[row][0] << ' '; // print cell data at [row][0], followed by a space.

	 cout << map[row][1] << ' '; // print cell data at [row][1], followed by a space.

	 cout << map[row][2] << ' '; // print cell data at [row][2], followed by a space.

	 cout << map[row][3] << ' '; // print cell data at [row][3], followed by a space.

	 cout << map[row][4] << ' '; // print cell data at [row][4], followed by a space.

	 cout << '\n'; // print a new line character

}



The five columns for the first row (row 0) are printed in sequence, followed by a new line character and then "row" is incremented by one and the next five columns for that row are printed and so on.

#1MarkS

Posted 06 December 2012 - 09:05 PM

To expand on what Alvaro said, nested loops do not run concurrently. The "column" for loop completes before control is given back to the "row" for loop. Another way of looking at that code snippet is:


for (row = 0; row < 5; ++row) {

	 cout << map[row][0] << ' ';

	 cout << map[row][1] << ' ';

	 cout << map[row][2] << ' ';

	 cout << map[row][3] << ' ';

	 cout << map[row][4] << ' ';

	 cout << '\n';

}



The five columns for the first row (row 0) are printed in sequence, followed by a new line character and then "row" is incremented by one and the next five columns for that row are printed and so on.

PARTNERS